Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[request]: GD support for image generation #137

Closed
elnath78 opened this issue Jun 26, 2023 · 6 comments
Closed

[request]: GD support for image generation #137

elnath78 opened this issue Jun 26, 2023 · 6 comments

Comments

@elnath78
Copy link

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
Copy link
Member

DASPRiD commented Jun 26, 2023

There is an open pull requests for an alternate GdLibRenderer, but that one hasn't been processed yet:
#114

@arxeiss
Copy link
Contributor

arxeiss commented Jul 1, 2023

@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
Copy link
Author

elnath78 commented Jul 1, 2023

@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
Copy link
Contributor

arxeiss commented Jul 2, 2023

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

  • Correction level is M
  • Input text is 140 chars length.
  • Final QR is 350x350 px and grid is 40x40 dots
  • GD (png) and Imagick (png) is ~80ms to draw with uniform colors.
  • Imagick with Gradient is ~180ms.

@elnath78
Copy link
Author

elnath78 commented Jul 3, 2023

@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
Copy link
Member

DASPRiD commented Mar 19, 2024

Resolved by #171

@DASPRiD DASPRiD closed this as completed Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants