-
-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathQRNetpbmAbstract.php
More file actions
66 lines (51 loc) · 1.58 KB
/
QRNetpbmAbstract.php
File metadata and controls
66 lines (51 loc) · 1.58 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
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Class QRNetbmAbstract
*
* @created 19.12.2025
* @author wgevaert & codemasher
* @copyright 2025 wgevaert & codemasher
* @license MIT
*/
declare(strict_types=1);
namespace chillerlan\QRCode\Output;
use chillerlan\QRCode\Output\QROutputAbstract;
use UnexpectedValueException;
use function sprintf;
abstract class QRNetpbmAbstract extends QROutputAbstract{
protected const HEADER_ASCII = '';
protected const HEADER_BINARY = '';
protected function getMagicNumber():string{
return $this->options->netpbmPlain ? static::HEADER_ASCII : static::HEADER_BINARY;
}
protected function getHeader():string{
$comment = 'created by https://github.com/chillerlan/php-qrcode';
return sprintf(
"%s\n# %s\n%s %s\n%s",
$this->getMagicNumber(),
$comment,
$this->length,
$this->length,
$this->getMaxValueHeaderString(),
);
}
protected function getMaxValueHeaderString():string {
if ( $this->options->netpbmMaxValue >= 65536 || $this->options->netpbmMaxValue <= 0 ) {
throw new UnexpectedValueException( 'NetpbmMaxValue should be between 0 and 65536' );
}
return $this->options->netpbmMaxValue."\n";
}
abstract protected function getBodyASCII():string;
abstract protected function getBodyBinary():string;
public function dump(string|null $file = null):string{
$qrString = $this->getHeader();
$qrString .= $this->options->netpbmPlain
? $this->getBodyASCII()
: $this->getBodyBinary();
$this->saveToFile($qrString, $file);
if($this->options->outputBase64){
$qrString = $this->toBase64DataURI($qrString);
}
return $qrString;
}
}