endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.45k stars 726 forks source link

Invalid content readed #309

Closed dominiquefournier closed 3 years ago

dominiquefournier commented 3 years ago

I just try to generate a QRCode with the following test code :

<?php
require_once ("vendor/autoload.php");

use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Label\Label;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;

$writer = new PngWriter();

// Create QR code
$qrCode = QrCode::create('708172c8-4627-4dc1-8b65-7bf33df8b440')
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
    ->setSize(300)
    ->setMargin(10)
;

$result = $writer->write($qrCode);
$result->saveToFile("/tmp/result.png");

But two material scanners are reading : "\000026708172c8-4627-4dc1-8b65-7bf33df8b440" If I use my smartphone the result is valid.

Here is the generated QRCode result

JanSlabon commented 3 years ago

This looks like an automatically added prefix of your material scanners/software. You should check their configuration.

dominiquefournier commented 3 years ago

It is not the case because I just scan an other QRCode and there is no added chars. It was my first reaction too.

dominiquefournier commented 3 years ago

Found ! If I use Encoding('ISO-8859-1'), the problem is solved. It was the UTF-8 definition which is 000026.

dominiquefournier commented 3 years ago

https://stackoverflow.com/questions/31115932/encoding-utf-8-characters-in-qr-code-symbols

weiting-sflx commented 1 year ago

@endroid is it possible to somehow configure to remove the #000026 prefix? The barcode scanner of our client is unable to scan the QR code because of that prefix.

endroid commented 1 year ago

Hi @weiting-sflx this is called an ECI block and it is necessary to correctly inform the reader that the text is in UTF-8. In other words it is not something that should be removed. If you rely heavily on a reader which is incapable of handling this information you can try changing the encoding to ISO-8859-1.

weiting-sflx commented 1 year ago

Hi @endroid Thanks for the response. We are an international company and encoding ISO-8859-1 is not supported in some languages such as Polish. We tried to use Google API for generating the QR code with the UTF-8 encoding and there is no ECI prefix.

endroid commented 1 year ago

I understand. As far as I can see the underlying library https://github.com/Bacon/BaconQrCode does not provide a toggle for adding this block. Maybe you can look and ask there to see if anything in this direction is possible (maybe using another encoding) or if the author can think of a solution. My library only passes the text and encoding to that library so this is not something I have control over from here.

weiting-sflx commented 1 year ago

We forked from the bacon library and your libraries. Will create PRs later.