Open Source
Open Source - Library

Introducing QR Code Library 4.0

Visit Our Github Repository
By
2am.
June 22, 2026
6 min read

PHP 8.5-Ready, ImageMagick-Free, and Framework-Agnostic

QR codes quietly run modern life: from menus, tickets, and payments, to Wi-Fi handoffs, and business cards. Our open-source QR Code Library has been helping PHP developers to generate them for years with a friendly, fluent API. 

It has grown to become one of our most used libraries with over 1.5 million downloads on Packagist and counting. Now, we are shipping our biggest release yet, a version 4.0.0. This is a ground-up modernization that is easier to install, simpler to run, cleaner to extend, and now usable from virtually any PHP framework. There’s also a brand new, first class support for Yii3 and the entire PSR-15 ecosystem.

This is what’s changed:

Built for modern PHP (8.3, 8.4 and 8.5)

4.0 targets PHP 8.3, 8.4, and 8.5, runs deprecation-free on all three, and is verified by a CI matrix on every push. We replaced the aging marc-mabe/php-enum polyfill (the Da\QrCode\Enums\* constants you already use are unchanged), upgraded to bacon/bacon-qr-code v3, and added PHPStan and php-cs-fixer to keep the codebase honest.

composer require 2amigos/qrcode-library:^4.0
use Da\QrCode\QrCode;

(new QrCode('https://2am.tech'))
    ->setSize(300)
    ->setMargin(10)
    ->writeFile(__DIR__ . '/qr.png');

Say goodbye to ImageMagick agony

This is the fix we're most proud of. Earlier, you required the ImageMagick extension if you wanted to silently generate a PNG or JPG, even though the library only listed ext-gd. On some configurations (Windows + XAMPP, I'm looking at you) that appeared as the cryptic:

ImagickException: RegistryKeyLookupFailed 'CoderModulesPath' @ error/module.c/GetMagickModulePath

ImageMagick is still fully supported, now as an explicit opt-in:

In version 4.0, a completely new pure-GD backend (Da\QrCode\Renderer\GdImageBackEnd) is the default renderer for PNG and JPG. It's a real rasterizer with scanline fills, bezier and arc flattening and gradients supported. The result: only ext-gd is required, the Windows error is gone, and everything just works out of the box.

Of course, ImageMagick is still fully supported, but now as an explicit opt-in:

use Da\QrCode\QrCode;
use Da\QrCode\Writer\PngWriter;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;

$qr = new QrCode('https://2am.tech', null, new PngWriter(new ImagickImageBackEnd('png')));

One library for every framework

QR code generation shouldn't depend on your tech stack. 4.0 reorganizes all the framework glue under a clean Da\QrCode\Bridge\<Framework>\ namespace, to keep the core framework-agnostic, and adds a new adapter that opens the door to everything else.

  • No framework required, works standalone:
echo (new \Da\QrCode\QrCode('Hello!'))->writeDataUri(); // data:image/png;base64,...
  • Laravel has a Blade component (auto-discovered service provider):
<x-2am-qrcode content="https://2am.tech" :size="300" />
  • Yii2 with a component and an action that you can wire up into your config and your controllers. Yii2 2.0.x works fine on PHP 8.3+, so it stays a first-class citizen:
'components' => [
    'qr' => ['class' => \Da\QrCode\Bridge\Yii2\QrCodeComponent::class],
],
  • Yii3 and any PSR-15 app (Mezzio, Slim, Laminas, and others). This is the headline addition. Da\QrCode\Bridge\Psr\QrCodeAction is a framework agnostic PSR-15 RequestHandlerInterface, that only depends on PSR-7 and PSR-17 interfaces. Set it up fluently (it’s immutable), point a route at it, and you have a QR endpoint:
use Da\QrCode\Bridge\Psr\QrCodeAction;

$action = (new QrCodeAction($responseFactory, $streamFactory))
    ->withSize(400)
    ->withForegroundColor(20, 30, 90);

$response = $action->handle($request); // GET /qr?text=https://2am.tech

In Yii3, register it in your container and bind a route:

// config/common/routes.php
Route::get('/qr')->action([QrCodeAction::class, 'handle'])->name('qr');

Thus, you get four ways to use a single library. And because the PSR-15 handler has a standard interface, it will slot into whatever framework you decide to use next.

Visually appealing QR codes

QR codes don’t have to be boring black and white squares. With the fluent API you can add colors, gradients, custom module shapes, logos, and labels:

use Da\QrCode\QrCode;
use Da\QrCode\Contracts\ErrorCorrectionLevelInterface;

(new QrCode('https://2am.tech', ErrorCorrectionLevelInterface::HIGH))
    ->setSize(400)
    ->setForegroundColor(20, 30, 90)
    ->setLogo(__DIR__ . '/logo.png')
    ->setLogoWidth(90)
    ->writeFile(__DIR__ . '/branded-qr.png');

4.0 also eliminates a long-standing bug where radial and inverse-diagonal gradients are rendered as a solid black block. They now render correctly across all writers (PNG, JPG, SVG, EPS).

Smarter data formats

The library ships ready-made encoders for all types of data people scan: Wi-Fi, vCard, MeCard, geo, calendar events, bitcoin, email, SMS, and more. Two of them got upgrades in 4.0:

  • Rather than just a remote URL, vCard PHOTO now accepts a Base64 data-URI or a local image file, inlined straight into the card (#69).
  • MeCard gained an ORG (organization) field (#34).
use Da\QrCode\Format\VCardFormat;

$vcard = new VCardFormat();
$vcard->name = 'Antonio Ramirez';
$vcard->photo = __DIR__ . '/avatar.png'; // inlined as Base64

echo (new \Da\QrCode\QrCode($vcard))->writeDataUri();

Engineered to last

4.0 has a healthier codebase under the hood. One less runtime dependency, a typed and statically analyzed core, a tuned PHPMD ruleset, php-cs-fixer formatting, and 97 tests that decode the generated codes to prove they actually scan. All running green on PHP 8.3, 8.4, and 8.5.

Upgrading from 3.x

4.0 is a major release with intentional and documented breaks: minimum PHP 8.3, GD backend by default (output bytes differ, and ImageMagick is opt-in), and framework adapters moved under Da\QrCode\Bridge\*. The full, copy-pasteable migration map is in UPGRADE-4.0.md. Most apps only need to touch a couple of use statements.

Get started

composer require 2amigos/qrcode-library:^4.0

No matter if you are on Laravel, Yii2, Yii3, a PSR-15 microframework or plain PHP, creating beautiful, reliably scannable QR codes just got a whole lot easier. 

A huge thanks to the community for pushing us to make this release the best one yet with over 1.5 million downloads.

Looking for a team that delivers clean, thoroughly tested, framework-agnostic code like this for your own product? That's what we do at 2am.tech. Let's talk about your project.

Contributors

Thank you all for your invaluable efforts!

Share This Post
Back to Open Source
Don't miss out on
our latest insights
– Subscribe Now!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Navigate
Start Now