Skip to content

Commit

Permalink
Use new ROUND_BLOCK_SIZE_MODE_ENLARGE
Browse files Browse the repository at this point in the history
This will make pixel based qr codes (like png) sharper and smaller in file size. On the other hand, the exact final image size may vary.
  • Loading branch information
sprain committed Jul 13, 2020
1 parent 6887030 commit 8f990a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 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"
},
"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

0 comments on commit 8f990a2

Please sign in to comment.