SimpleSoftwareIO / simple-qrcode

An easy-to-use PHP QrCode generator with first-party support for Laravel.
https://www.simplesoftware.io/simple-qrcode
MIT License
2.74k stars 391 forks source link

qrcode merge error #193

Closed lyekumchew closed 3 years ago

lyekumchew commented 4 years ago

When a picture with transparency (PNG) is merged into a QR code, the four red boxes display the transparent part instead of the QR code. I can't do it like a demo.

image image

$qrcode = 'data:image/png;base64,'.base64_encode(QrCode::format('png')->merge('https://avatars0.githubusercontent.com/u/7749926?s=400&v=4',
            .32, true)->errorCorrection('H')->size(500)->generate($url));

simple-qrcode version: 3.0.0 PHP 7.3.23 (cli) (built: Oct 1 2020 21:10:33) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.23, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.23, Copyright (c) 1999-2018, by Zend Technologies

bilogic commented 4 years ago

@lyekumchew could it be because your image has no transparency?

lyekumchew commented 4 years ago

@lyekumchew could it be because your image has no transparency?

The four red frames on the image show white because my background color is white. If it is black, the four places are shown as black. Merge images are mentioned in the code.

https://avatars0.githubusercontent.com/u/7749926?s=400&v=4

SimplyCorey commented 4 years ago

Interesting. Is this happening on 4.0.0?

lyekumchew commented 4 years ago

Interesting. Is this happening on 4.0.0?

I've tried versions 3.0.0 and 4.0.0, both of which have this problem.

SimplyCorey commented 4 years ago

Thanks for reporting. It appears to be an image transparency bug with the PNG resampling. The method calls will need to be adjusted to fix this correctly. I'll resolve it when I have time, or if someone want to jump in you can find the code here: https://github.com/SimpleSoftwareIO/simple-qrcode/blob/develop/src/ImageMerge.php#L110

SimplyCorey commented 4 years ago

This will likely be fixed with https://github.com/SimpleSoftwareIO/simple-qrcode/issues/192

bilogic commented 4 years ago

@SimplyCorey can I ask why we need ext-magick? For the gradient rendering?

muarachmann commented 4 years ago

@SimplyCorey , @bilogic I achieved this a couple of days back. The idea is to create a transparent background with the image. If @bilogic is on this fine, I can pass else I could send a PR. Here is what I got. I could blend any image at any point. NB I made it transparent cause I needed to achieve the twitter QR code effect. Check https://twitter.com/muarachmann/status/1312453668520693762?s=20

qr_contact

muarachmann commented 4 years ago

@SimplyCorey can I ask why we need ext-magick? For the gradient rendering?

This extension in general is needed to manipulate images in php. just like you will need mysqli to connect to any mysql db instance. This doesn't come by default with php i think so you need to install it. You can as well go with gd I think

bilogic commented 4 years ago

@muarachmann I asked because endroid did not need ext-magick, and I never had to use it too even though I generate PNGs for other purposes.

muarachmann commented 4 years ago

@muarachmann I asked because endroid did not need ext-magick, and I never had to use it too even though I generate PNGs for other purposes.

Yes @bilogic they use GD see https://github.com/endroid/qr-code/issues/233 like I said you can have one or use the other. Either way, you must have one of these image Library. I think here imagick was the preferred one

SimplyCorey commented 4 years ago

I'm kind of surprised endroid doesn't require ext-magick as they use the same underlying qrcode library. They must have created their own writer to get around that.

@muarachmann I would be interested in seeing a PR and how you went about this. It might solve #192 as well although that might take a different approach to make the overlays look cleaner.

bilogic commented 4 years ago

@SimplyCorey

  1. Does https://github.com/Bacon/BaconQrCode render PNGs? (My understanding is they don't)
  2. Anyway, if gradient was not the reason for ext-magick, perhaps you want to consider moving to gd?

I know I'm digressing, let me know if I should open another issue. Thanks.