Skip to content

Commit

Permalink
Merge pull request #67 from sprain/reduce-png-filesize
Browse files Browse the repository at this point in the history
Adjust rounding of qr code blocks for smaller png file size
  • Loading branch information
sprain authored Jul 13, 2020
2 parents 6887030 + 3a13070 commit 04f5edb
Show file tree
Hide file tree
Showing 115 changed files with 68 additions and 63 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"symfony/intl": "^3.4|^4.2|^5.0",
"khanamiryan/qrcode-detector-decoder": "^1.0.3",
"kmukku/php-iso11649": "^1.5",
"endroid/qr-code": "^3.8.2"
"endroid/qr-code": "^3.9.1"
},
"require-dev": {
"phpunit/phpunit": "^6.4|^7.0",
Expand Down
16 changes: 9 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/QrBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class QrBill implements SelfValidatableInterface

private const SWISS_CROSS_LOGO_FILE = __DIR__ . '/../assets/swiss-cross.optimized.png';

private const PX_QR_CODE = 543; // recommended 46x46 mm in px @ 300dpi – in pixel based outputs, the final image size may be slightly different, depending on the qr code contents
private const PX_SWISS_CROSS = 83; // recommended 7x7 mm in px @ 300dpi

/** @var Header */
private $header;

Expand Down Expand Up @@ -195,11 +198,11 @@ public function getQrCode(): QrCode

$qrCode = new QrCode();
$qrCode->setText($this->getQrCodeContent());
$qrCode->setSize(543); // recommended 46x46 mm in px @ 300dpi
$qrCode->setLogoHeight(83); // recommended 7x7 mm in px @ 300dpi
$qrCode->setLogoWidth(83); // recommended 7x7 mm in px @ 300dpi
$qrCode->setSize(self::PX_QR_CODE);
$qrCode->setLogoHeight(self::PX_SWISS_CROSS);
$qrCode->setLogoWidth(self::PX_SWISS_CROSS);
$qrCode->setLogoPath(self::SWISS_CROSS_LOGO_FILE);
$qrCode->setRoundBlockSize(false);
$qrCode->setRoundBlockSize(true, \Endroid\QrCode\QrCode::ROUND_BLOCK_SIZE_MODE_ENLARGE);
$qrCode->setMargin(0);
$qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel($this->errorCorrectionLevel));

Expand Down
Binary file modified tests/TestData/FpdfOutput/qr-additional-information.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-additional-information.print.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-alternative-schemes.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-alternative-schemes.print.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-full-set.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-full-set.print.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-minimal-setup.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-minimal-setup.print.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-payment-reference-non.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-payment-reference-non.print.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-payment-reference-scor.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-payment-reference-scor.print.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-ultimate-debtor.pdf
Binary file not shown.
Binary file modified tests/TestData/FpdfOutput/qr-ultimate-debtor.print.pdf
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-alternative-schemes.png.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-alternative-schemes.svg.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-full-set.png.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-full-set.png.print.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-full-set.svg.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-full-set.svg.print.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-minimal-setup.png.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-minimal-setup.png.print.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-minimal-setup.svg.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-minimal-setup.svg.print.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-ultimate-debtor.png.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/TestData/HtmlOutput/qr-ultimate-debtor.svg.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions tests/TestData/QrCodes/TestDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public function testQrFile($file, $hash)
public function qrFileProvider()
{
return [
[__DIR__ . '/qr-additional-information.png', 'fb9c45f2bc0bf92e941abc64ba50bebb'],
[__DIR__ . '/qr-alternative-schemes.png', '138ac88c4f5d9d127fb11326daa9292a'],
[__DIR__ . '/qr-full-set.png', '969b870f49362a611f62235190fcf03a'],
[__DIR__ . '/qr-minimal-setup.png', '8ed64ec5a2c7a02b1e07aa5eb8e3a7a0'],
[__DIR__ . '/qr-payment-information-without-amount.png', '831b0edb4aca22f5df5f8dec530461dc'],
[__DIR__ . '/qr-payment-information-without-amount-but-debtor.png', '9d4db076385276242cc4a362ee29b58d'],
[__DIR__ . '/qr-payment-information-zero-amount.png', '1e35e396920f07fd0933ecdaabe910f9'],
[__DIR__ . '/qr-payment-reference-non.png', 'abb3ace7ea9f3ef848a335eba98a2375'],
[__DIR__ . '/qr-payment-reference-scor.png', '7e3389311c54ff27e1537d1083656a07'],
[__DIR__ . '/qr-ultimate-debtor.png', 'ac5d8f4155c1d10460de5a0aaea35767'],
[__DIR__ . '/qr-additional-information.png', '3a23f70cc8cf519f66d27b73f002d828'],
[__DIR__ . '/qr-alternative-schemes.png', '5bba5e41336c8e22fa50bea7627da41c'],
[__DIR__ . '/qr-full-set.png', '766de4a121a49a7e88dacce508f1588f'],
[__DIR__ . '/qr-minimal-setup.png', '069e274f22816fcdd799acb1c0cc1dd9'],
[__DIR__ . '/qr-payment-information-without-amount.png', '5705acaab9b9219884fdb2bc99c2cfce'],
[__DIR__ . '/qr-payment-information-without-amount-but-debtor.png', '281316342f09a85af4ad137dc4d30998'],
[__DIR__ . '/qr-payment-information-zero-amount.png', 'aac0aef35bd36e9b79e903998db4756f'],
[__DIR__ . '/qr-payment-reference-non.png', '2e1ebe0623baf0f52922c2e6b988bcc6'],
[__DIR__ . '/qr-payment-reference-scor.png', '03daab8e7c66094bbef308236882c739'],
[__DIR__ . '/qr-ultimate-debtor.png', '5c359ee3333833a54a2076e5e83d2d20'],

[__DIR__ . '/proof-of-validation.png', '6bf37bad5b10f54971068a90de36fd0e'],
[__DIR__ . '/proof-of-validation.png', '7d13a8739e490b3cdf13d7d86f66d6cb'],
];
}
}
Binary file modified tests/TestData/QrCodes/proof-of-validation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-additional-information.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-alternative-schemes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-full-set.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-minimal-setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-payment-information-without-amount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-payment-information-zero-amount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-payment-reference-non.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-payment-reference-scor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/QrCodes/qr-ultimate-debtor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/TestData/TcPdfOutput/qr-additional-information.png.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-additional-information.svg.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-alternative-schemes.png.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-alternative-schemes.png.print.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-alternative-schemes.svg.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-alternative-schemes.svg.print.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-full-set.png.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-full-set.png.print.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-full-set.svg.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-full-set.svg.print.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-minimal-setup.png.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-minimal-setup.png.print.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-minimal-setup.svg.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-minimal-setup.svg.print.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-payment-reference-non.png.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-payment-reference-non.svg.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-payment-reference-scor.png.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-payment-reference-scor.svg.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-ultimate-debtor.png.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-ultimate-debtor.png.print.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-ultimate-debtor.svg.pdf
Binary file not shown.
Binary file modified tests/TestData/TcPdfOutput/qr-ultimate-debtor.svg.print.pdf
Binary file not shown.

0 comments on commit 04f5edb

Please sign in to comment.