-
-
Notifications
You must be signed in to change notification settings - Fork 330
Add QRPbm output format for Portable BitMap outputs #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wgevaert
wants to merge
17
commits into
chillerlan:main
Choose a base branch
from
wgevaert:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0a069c3
Add QRPbm output format for Portable BitMap outputs
wgevaert e70a744
Add pbm output to readme
wgevaert f5a2d2b
Actually run tests against new class
wgevaert aa748d2
Formatting
wgevaert 9b94cfe
Call instance methods non-statically
wgevaert aff03cc
Also support binary bitmaps
wgevaert 78ae3a3
Missing import
wgevaert 03802e8
Formatting
wgevaert ddef97d
Formatting
wgevaert e5f60fd
Remove superseded QRPbm class
wgevaert a520c0f
Add mime type and return base64 if needed
wgevaert b2f1286
Add grayscale, and incorporate suggestions from review
wgevaert a9eda61
Add support for Pixmap and fix codestyle
wgevaert ce85a50
Remove now obsolete classes
wgevaert 5182a50
Bugfixes and review comment changes
wgevaert 2bb89f8
Add tests
wgevaert e6f3319
Remove superfluous check on maxvalue
wgevaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?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; | ||
|
|
||
| class QRPbm extends QROutputAbstract { | ||
|
|
||
| private const LIGHT_DARK = [ '0', '1' ]; | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
|
|
||
| protected function prepareModuleValue( mixed $value ): mixed { | ||
| return $value; | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| protected function getDefaultModuleValue( bool $isDark ): mixed { | ||
| return $isDark ? self::LIGHT_DARK[1] : self::LIGHT_DARK[0]; | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public static function moduleValueIsValid( mixed $value): bool { | ||
| return is_string( $value ) && in_array( $value, self::LIGHT_DARK, true ); | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public function dump( string|null $file = null ): mixed { | ||
| $size = $this->matrix->getSize(); | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| $qrString = "P1\n" | ||
| .$size.' '.$size."\n"; | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| foreach($this->matrix->getBooleanMatrix() as $row) { | ||
| foreach ($row as $isDark) { | ||
| $qrString .= $this->getDefaultModuleValue( $isDark ); | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| } | ||
| $qrString .= "\n"; | ||
| } | ||
| if ( is_string($file) ) { | ||
| $writeResult = file_put_contents($file,$qrString); | ||
| if ( $writeResult === false ) { | ||
| throw new QRCodeOutputException('Cannot write data to cache file: '.$file); | ||
| } | ||
| } | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| return $qrString; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
| /** | ||
| * Class QRPbmTest | ||
| * | ||
| * @created 11.12.2025 | ||
| * @author wgevaert | ||
| * @copyright 2025 wgevaert | ||
| * @license MIT | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace chillerlan\QRCodeTest\Output; | ||
|
|
||
| use chillerlan\QRCode\QROptions; | ||
| use chillerlan\QRCode\Data\QRMatrix; | ||
| use chillerlan\QRCode\Output\{QROutputInterface, QRPbm}; | ||
| use chillerlan\Settings\SettingsContainerInterface; | ||
| use PHPUnit\Framework\Attributes\Test; | ||
|
|
||
| /** | ||
| * Tests the QRPbm output class | ||
| */ | ||
| final class QRPbmTest extends QROutputTestAbstract{ | ||
|
|
||
| protected function getOutputInterface( | ||
| SettingsContainerInterface|QROptions $options, | ||
| QRMatrix $matrix, | ||
| ):QROutputInterface{ | ||
| return new QRPbm($options, $matrix); | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-return array<string, array{0: mixed, 1: bool}> | ||
| */ | ||
| public static function moduleValueProvider():array{ | ||
| return [ | ||
| 'invalid: wrong type' => [[], false], | ||
| 'invalid: Not 0 or 1' => ['abc', false], | ||
| 'invalid: empty string' => ['', false], | ||
| 'invalid: space string' => [' ', false], | ||
| 'valid: zero' => ['0', true], | ||
| ]; | ||
| } | ||
|
|
||
| #[Test] | ||
| public function setModuleValues():void{ | ||
|
|
||
| $this->options->moduleValues = [ | ||
| // data | ||
| QRMatrix::M_DATA_DARK => '1', | ||
| QRMatrix::M_DATA => '0', | ||
| ]; | ||
|
|
||
| $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix); | ||
| $data = $this->outputInterface->dump(); | ||
|
|
||
| $this->assertStringContainsString('1', $data); | ||
| $this->assertStringContainsString('0', $data); | ||
|
wgevaert marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.