- How do I install bacon/bacon-qr-code in a Laravel application?
- Run composer require bacon/bacon-qr-code:^3.1 in your Laravel project. The package requires PHP 8.1 or newer and has no Laravel service provider, config file, or migrations to publish, so installation is just the Composer dependency plus a small wrapper class of your own. Confirm your production and CI images have ext-xmlwriter for SVG output, or ext-gd / ext-imagick if you need raster images.
- Does bacon/bacon-qr-code support Laravel 11 and Laravel 12?
- Yes. BaconQrCode is framework-agnostic plain PHP, so any Laravel version running on PHP 8.1+ can use v3.x. Laravel releases are irrelevant to the library itself, which only cares about your PHP version and installed extensions. Projects still on PHP 7.x or 8.0 must stay on BaconQrCode v2 or upgrade PHP first.
- Which renderer should I use: ImagickImageBackEnd, SvgImageBackEnd, or GDLibRenderer?
- Prefer SvgImageBackEnd for web pages, emails, and print-friendly scaling, since it requires only ext-xmlwriter and produces clean vector output. GDLibRenderer is a good choice for simple squared PNGs with ext-gd, but it supports no gradients or curved modules. ImagickImageBackEnd works but has a documented white-pixel artifact bug that maintainers cannot reliably work around, so avoid it where pixel-perfect output matters.
- Do I need a service provider to use BaconQrCode in Laravel?
- No. The library ships no service provider, config, or global state, so it can be treated as an implementation detail. The recommended pattern is to define your own interface, such as QrCodeGenerator with svg() and png() methods, bind a default renderer in a Laravel service provider, and keep BaconQrCode types out of controllers and domain code.
- Can BaconQrCode read or decode QR codes?
- No, BaconQrCode is encoder-only. It generates QR codes but cannot scan, decode, or verify them. If you need verification, use a separate decoding library, a mobile scanner, or your platform camera workflow.
- How do I return an SVG QR code from a Laravel controller?
- Build a Writer with SvgImageBackEnd, call writeString() to get the SVG markup, then return a response with the image/svg+xml content type and the markup as the body. Because generation is cheap but not free, cache the resulting SVG with Laravel Cache or persist it to Laravel Storage keyed by payload and options. Always escape or validate user-controlled payload data before embedding it in links or signed URLs.
- What PHP extensions does bacon/bacon-qr-code require?
- The SvgImageBackEnd requires ext-xmlwriter, ImagickImageBackEnd requires ext-imagick, and GDLibRenderer requires ext-gd; EPS output needs no extra extension. Since these are runtime requirements, verify them in production, CI, and every developer environment, not just locally. Keep the dependency constraints narrow so a surprise major release does not change output unexpectedly.
- How do I add a logo, gradient, or custom styling to a QR code with BaconQrCode?
- BaconQrCode does not composite logos or brand images for you, so overlay a logo afterwards with GD or Imagick, or edit the generated SVG markup directly. If you only need square modules with a solid color, GDLibRenderer is sufficient, but gradients and curved modules are not supported there. When adding a logo, raise the error correction level, keep a generous quiet zone, and test scanability on real devices.
- How does bacon/bacon-qr-code compare to simplesoftwareio/simple-qrcode?
- simple-qrcode is a convenience wrapper that renders through BaconQrCode, so you are already using this encoder indirectly if that package is installed. If you migrate, replace the wrapper API with your own interface and keep output compatible through snapshot tests. Migrating from endroid/qr-code is more involved because the renderer APIs differ, so compare golden SVG or PNG output before switching.
- How should I test QR code generation in Laravel and CI?
- Write feature tests around your own QrCodeGenerator interface rather than asserting on BaconQrCode internals, and use SVG snapshot or golden-image tests to catch renderer changes. Cover representative payloads, UTF-8 and ECI behavior, maximum capacity, and margin or size options. Make sure CI installs the same PHP extensions as production, because a missing ext-xmlwriter or ext-gd will fail only at render time.