-
-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathQRNetpbmBitmapBinary.php
More file actions
38 lines (33 loc) · 868 Bytes
/
QRNetpbmBitmapBinary.php
File metadata and controls
38 lines (33 loc) · 868 Bytes
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
<?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\QRNetpbmBitmapAbstract;
class QRNetpbmBitmapBinary extends QRNetpbmBitmapAbstract {
protected function getHeader(): string {
return 'P4';
}
protected function getBody(): string {
$asciiBody = parent::getBody();
$body = '';
foreach (explode("\n", $asciiBody) as $row) {
$body .= $this->asciiBinToBinary( $row );
}
return $body;
}
private function asciiBinToBinary( string $asciiBin ): string {
$binaryString = '';
foreach(str_split( $asciiBin, 8 ) as $currentChunk) {
$currentChunk = str_pad( $currentChunk, 8, '0' );
$binaryString .= pack( 'C', bindec( $currentChunk ) );
}
return $binaryString;
}
}