gitmyhub

qr-code

PHP ★ 4.8k updated 4mo ago

PHP QR Code library that helps you create QR codes in a jiffy

A PHP library for generating QR codes in PNG, SVG, WebP, EPS, and PDF formats, with support for custom colors, logos in the center, text labels, and adjustable error correction levels.

PHPComposerSymfonyTwigsetup: easycomplexity 2/5

This is a PHP library for generating QR codes, which are the square barcodes commonly used to encode URLs and other short pieces of text that can be scanned by a phone camera. The library handles the math of building the QR code pattern and then outputs the result as an image file in a format you choose.

The library supports several output formats: PNG, WebP, SVG, EPS, and PDF. You can control the size of the QR code, the amount of margin around it, the colors of the dark and light squares, and the error correction level. Error correction determines how much of the code can be damaged or obscured and still scan successfully. Higher correction means a more complex pattern but greater tolerance for things like printing defects or logos placed on top.

Adding a logo image in the center of a QR code is supported directly. You provide an image path and a size, and the library places it over the code. Because the logo covers part of the pattern, the error correction level needs to be set high enough that the obscured portion does not prevent the code from scanning. The library also supports adding a text label below the QR code with control over font and alignment.

For PHP projects using the Symfony framework there is a companion bundle that wires up QR code generation as a service and exposes URL routes for generating codes on request, which is useful for generating codes server-side in response to web requests. There is also a Twig extension for generating QR codes directly inside HTML templates.

The library includes an optional validation step that, after generating a QR code, immediately decodes it and checks that the result matches the original input. This catches any rare cases where the generated code is unreadable, though it adds processing time so it is off by default. Installation uses Composer, the standard PHP package manager.

Where it fits