endroid / qr-code

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

v4: PngWriter creates blurry shapes #355

Closed sprain closed 2 years ago

sprain commented 3 years ago

I noticed with v4 that qr codes written as png become blurry while in v3 the same setup created razor sharp images. See the following two examples and zoom into the qr codes to see the difference. The difference is also clearly detectable in file size.

I experimented with different RoundBlockSizeModes which did not change this effect. I also tried different enviroments (e.g. PHP 7.3 vs PHP 8) with no change to this behaviour.

v3.9.7

$data = "AAAABBBBCCCCDDDD";

$qrCode = new QrCode($data);
$qrCode->setSize(300);
$qrCode->setMargin(0); 
$qrCode->setEncoding('UTF-8');
$qrCode->setWriterByName('png');

$qrCode->writeFile(__DIR__.'/qrcode.png');

qrcode


v4.3.5

$data = "AAAABBBBCCCCDDDD";

$result = Builder::create()
    ->data($data)
    ->size(300)
    ->margin(0)
    ->encoding(new Encoding('UTF-8'))
    ->writer(new PngWriter())
    ->build();

$result->saveToFile(__DIR__.'/qrcode.png');

qrcode


The blurry effect can also be seen in this comment here – so it does not only happen to me: https://github.com/endroid/qr-code/issues/348#issuecomment-920734030

endroid commented 2 years ago

Hi @sprain thank you. This should be fixed in 4.4.3.

sprain commented 2 years ago

Awesome! Thank you! I did try to fix it but could not find the issue. Very glad you did 😊