Bacon / BaconQrCode

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

[request]: GD support for image generation #137

Closed elnath78 closed 5 months ago

elnath78 commented 1 year ago

I'm not sure ifthis was already discussed, but I find much more practical to have GD support than Imagick, iirc GD is natively present in recent PHP intallations, while Imagick must be installed separately, configured and you need to pray it works.

DASPRiD commented 1 year ago

There is an open pull requests for an alternate GdLibRenderer, but that one hasn't been processed yet: https://github.com/Bacon/BaconQrCode/pull/114

arxeiss commented 1 year ago

@elnath78 as noted above, there is open PR for that. If you want, add this to your composer.json. It works, I'm using it on production for one client. And trying to keep up to date with latest changes.

P.S. There is another reason not to use Imagick. When QR code is too large it was failing for me locally with some kind a weird exception that the path was too complex.

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/arxeiss/BaconQrCode"
        }
    ],
    "require": {
        ...
        "bacon/bacon-qr-code": "dev-add-gd-backend#650e10121f4d8707ecdc5984b042cae7731e388a",
elnath78 commented 1 year ago

@arxeiss I tried the Bacon path but it is incredibly slow, tested on local and it averaged 1.76 seconds to generate a QR code, I tested the various available formats. Eventually I decided to use the Google service for QR Code generation, and although it does a remote connection, it is super fast, the average was 0.08 seconds. The only concern is about GDPR, the other possible solution would be generate QR Codes then serve them as users join and request them, possibly an async service that generate a QR Code when the user signs up and serve it ready when he decides to switch to 2FA login.

arxeiss commented 1 year ago

How big your QR code is? I tested it locally:

elnath78 commented 1 year ago

@arxeiss This is what I did, using multiple formats as well:

use BaconQrCode\Renderer\ImageRenderer;
//use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
//use BaconQrCode\Renderer\Image\EpsImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;

$renderer = new ImageRenderer(
    new RendererStyle(300),
    new SvgImageBackEnd()
);

//$uri has the URL formatted for QR Code
$writer = new Writer($renderer);
$writer->writeFile($uri, 'qrcode.svg');
DASPRiD commented 5 months ago

Resolved by #171