0

My question is pretty close to QR Code Generator Library (no web service) – just for PHP instead of .NET: I want a small, light-weight PHP "library" (ideally a compact class) to generate QR Codes, mostly for texts. It shall not use any web services, but generate the codes on-site.

Requirements

  • free and open source (FOSS/FLOSS)
  • small and light-weight (ideally a single class file with max 50kiB)
  • the "simple" from the title meaning: install via copy-the-file(s) must be possible – not e.g. requiring composer with 10 dependencies. Best no dependencies at all (except for "built-in"/ships-with-PHP, like php-gd to create/manipulate graphics)
  • not using web services (local generation; can use e.g. php-gd to generate images)
  • supports at least encoding text and URLs
  • supports at least PHP 7+

Nice to have (but not strictly required)

  • supporting other types, like VCards, calendar entries
  • embedding logos (to make a QR code easier to identify visibly)
  • setting foreground/background colors (if not possible, black on white is OK)
  • setting size (could be done afterwards – but it's easier if supported directly)
  • small resulting file size
  • actively maintained (so support for future PHP versions has a chance)
  • available at Github, GitLab or Codeberg, ideally incl. issue tracker (for support, feedback and possible contributions)

Not needed

  • fancy stuff like crazy coloring or rotating QR cubes with sound (you know what I mean: KISS principle)
1

There are many libraries to perform such a task. Here's the ones that caught my attention:

php-qrcode: simple, but supports many options:

echo '<img src="'.(new QRCode)->render("hello world").'" />';

qr-code: same:

use Endroid\QrCode\QrCode;
$qrCode = new QrCode('Life is too short to be generating QR codes');
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();

phpqrcode: open source library, based on libqrencode.

<?php 
include('qrlib.php'); 
// outputs image directly into browser, as PNG stream 
QRcode::png('hello world');
  • 1
    Sounds nice. I forgot to explain "simple" it seems: 1) requires composer (and dependencies), so it's unfortunately out (a simple copy must suffice). 2) also requires composer, so same. 3) was last released 2010 (so not sure if it supports PHP 7 at all). Actually I had already seen 1+3 and ruled them out for the reasons given. Thanks & +1 nevertheless! My fault of not being detailed enough, will update my question accordingly. – Izzy Apr 14 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.