-
-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathQRNetpbmBitmapAbstract.php
More file actions
55 lines (45 loc) · 1.28 KB
/
QRNetpbmBitmapAbstract.php
File metadata and controls
55 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Class QRPbm
*
* @created 11.12.2025
* @author wgevaert
* @copyright 2025 wgevaert
* @license MIT
*/
declare(strict_types=1);
namespace chillerlan\QRCode\Output;
use chillerlan\QRCode\Output\QROutputAbstract;
abstract class QRNetpbmBitmapAbstract extends QROutputAbstract {
protected function prepareModuleValue( mixed $value ): mixed {
if ( !is_bool( $value ) ) {
throw new UnexpectedValueException( "Expected boolean module value" );
}
return $value;
}
protected function getDefaultModuleValue( bool $isDark ): bool {
return $isDark;
}
public static function moduleValueIsValid( mixed $value ): bool {
return is_bool( $value );
}
abstract protected function getHeader(): string;
protected function getBody(): string {
$body = '';
foreach ( $this->matrix->getBooleanMatrix() as $row ) {
$line = '';
foreach ($row as $isDark) {
$line .= str_repeat( $isDark ? '1' : '0', $this->scale );
}
$line .= "\n";
$body .= str_repeat( $line, $this->scale );
}
return trim($body,"\n");
}
public function dump( string|null $file = null ): mixed {
$qrString = $this->getHeader() . "\n"
.$this->length.' '.$this->length."\n".$this->getBody();
$this->saveToFile( $qrString, $file );
return $qrString;
}
}