Bacon / BaconQrCode

QR Code Generator for PHP
BSD 2-Clause "Simplified" License
1.83k stars 208 forks source link

No way to specify input is bytes #82

Closed kategray closed 3 years ago

kategray commented 3 years ago

Hello,

I'm compressing some data before encoding the QR code to save space, but there doesn't seem to be a way to specify that the input should be left as is, without character set handling.

Attempting to use a BZCompressed string with the encoder gives me an error like the following:

Stack trace:
#0 /home/kate/Projects/QRCode/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php(511): BaconQrCode\Encoder\Encoder::append8BitBytes()
#1 /home/kate/Projects/QRCode/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php(76): BaconQrCode\Encoder\Encoder::appendBytes()
#2 /home/kate/Projects/QRCode/vendor/bacon/bacon-qr-code/src/Writer.php(52): BaconQrCode\Encoder\Encoder::encode()
#3 /home/kate/Projects/QRCode/vendor/bacon/bacon-qr-code/src/Writer.php(66): BaconQrCode\Writer->writeString()
#4 /home/kate/Projects/QRCode/test.php(59): BaconQrCode\Writer->writeFile()
#5 {main}
  thrown in /home/kate/Projects/QRCode/vendor/bacon/bacon-qr-code/src/Encoder/Encoder.php on line 598

Would this be an appropriate use for CP437?

DASPRiD commented 3 years ago

This is a limitation introduced by the way the encoder is implemented based on the original Zxing encoder. Usually people work around that by encoding binary data in e.g. ASCII85 or similar, which has very low storage efficiency loss:

https://stacktranslate.com/en/question/2036/store-binary-data-qr-code-zxing-java-library

kategray commented 3 years ago

Thank you.