Skip to content

QR Code Generator PHP: 5 Formats, Zero Dependencies

QR Code Generator PHP: 5 Formats, Zero Dependencies

A QR code looks like a solved problem until someone needs a hundred thousand of them for printed labels. Then the wrapper around a JavaScript library either needs Node on the server or sends data to a third party. A qr code generator php that runs in the request and carries no dependencies removes both.

Code: phpQRcode, MIT licensed.

composer require globus-studio/phpqrcode, PHP 7.4 up to 9.0, and one line to produce the image.

One call, five outputs

QRCode::svg('https://example.com');

SVG is the default because it prints. A code on a label, a business card or a poster goes to a printer, and SVG scales without a pixel decision. png(), html(), string() and matrix() cover the other cases: email, a table-based template, a terminal, and code that needs the raw grid.

The last one matters more than it sounds. A matrix is what a designer tool, a PDF generator or a canvas needs, and most libraries keep it private.

Error correction is a business decision

Four levels: L at roughly 7% recovery, M at 15%, Q at 25%, H at 30%. A code printed on a van and photographed in the rain needs H. A code on a screen needs L and stays small.

The library exposes the level as an enum, so the choice is visible in the code rather than buried in a default.

The mask is the performance switch

By default the encoder tests all eight mask patterns and picks the best, which costs about 180 milliseconds per code. Pass a fixed mask from 0 to 7 and it drops to about 11 milliseconds, seventeen times faster.

For a single invoice that is irrelevant. For a batch of fifty thousand labels it is the difference between a job that finishes and a job that is still running at lunch. The trade is a slightly less optimal pattern, which a scanner does not care about.

Where the numbers come from

186 tests, 2209 assertions, coverage around 100%, PHPStan at the maximum level, and support for PHP 7.4 through 9.0.

That range is the part a client feels. A generator that requires PHP 8.2 forces an upgrade on a server that hosts ten other sites, and an upgrade on a shared host is a project, not a task.

Why no dependencies

The encoder is arithmetic and a matrix. ext-gd is needed only for PNG, and every other renderer is pure PHP.

For a security audit that is one less supply chain, and for a hosting migration it is one less extension to install. The same reasoning appears in the other tools I ship, and it is not modesty: a QR library is small enough to own.

Where it pays

Three jobs repeat in client work: an invoice with a payment code, a stock label with a product code, and a ticket with a check-in code. Each one needs a code inside an existing page or PDF, and each one fails when the only way to get it is a third-party image service.

A library in the request means the code is generated where the data already is. No API key, no rate limit, no image URL that breaks when a service changes its terms.

What it does not do

It does not read QR codes, does not style a code with a logo inside, and does not decide what to put in the payload. A logo in the middle eats error correction, and the level someone chose for a rainy van is exactly what a logo consumes.

Related: wordpress plugin development for where a QR generator usually gets wired in, and PHP development for how a small library changes a quote.