A QR Code generator for PHP7.4+

Last update: Aug 8, 2022

chillerlan/php-qrcode

A PHP 7.4+ QR Code library based on the implementation by Kazuhiko Arase, namespaced, cleaned up, improved and other stuff.

PHP Version Support Packagist version License CodeCov Scrunitizer CI Packagist downloads
Continuous Integration

Documentation

See the wiki for advanced documentation. An API documentation created with phpDocumentor can be found at https://chillerlan.github.io/php-qrcode/ (WIP).

Requirements

  • PHP 7.4+
    • ext-mbstring
    • optional:

Installation

requires composer

via terminal: composer require chillerlan/php-qrcode

composer.json

{
	"require": {
		"php": "^7.4",
		"chillerlan/php-qrcode": "dev-main"
	}
}

Note: replace dev-main with a version constraint, e.g. ^3.2 - see releases for valid versions. For PHP version ...

  • 7.4+ use ^4.3
  • 7.2+ use ^3.4.1 (v3.4.1 also supports PHP8)
  • 7.0+ use ^2.0
  • 5.6+ use ^1.0 (please let PHP 5 die!)

In case you want to keep using dev-main, specify the hash of a commit to avoid running into unforseen issues like so: dev-main#b625396e0752d79747a55205ae7e191eeb459dcd

PSA: PHP 7.0 - 7.3 are EOL and therefore the respective QRCode versions are also no longer supported!

Quickstart

We want to encode this URI for a mobile authenticator into a QRcode image:

$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';

// quick and simple:
echo '<img src="'.(new QRCode)->render($data).'" alt="QR Code" />';

QR codes are awesome!

Wait, what was that? Please again, slower! See Advanced usage on the wiki.

Framework Integration

Shameless advertising

Hi, please check out my other projects that are way cooler than qrcodes!

Disclaimer!

I don't take responsibility for molten CPUs, misled applications, failed log-ins etc.. Use at your own risk!

License notice

Parts of this code are ported to php from the ZXing project and licensed under the Apache License, Version 2.0.

Trademark Notice

The word "QR Code" is a registered trademark of DENSO WAVE INCORPORATED
https://www.qrcode.com/en/faq.html#patentH2Title

GitHub

https://github.com/chillerlan/php-qrcode
Comments
  • 1. QRCode image with logo and colors not working

    It return the image black and white and not with colors as shown in examples

    	$options = new QRCodeLogoOptions;
    
    	$options->version          = 5;
    	$options->eccLevel         = QRCode::ECC_H;
    	$options->imageBase64      = false;
    	$options->logoSpaceWidth   = 13;
    	$options->logoSpaceHeight  = 13;
    	$options->scale            = 5;
    	$options->imageTransparent = false;
    	
    	$options2 = new QROptions([
    		'version'      => 7,
    		'outputType'   => QRCode::OUTPUT_IMAGICK,
    		'eccLevel'     => QRCode::ECC_H,
    		'scale'        => 5,
    		'moduleValues' => [
    			// finder
    			1536 => '#A71111', // dark (true)
    			6    => '#FFBFBF', // light (false)
    			// alignment
    			2560 => '#A70364',
    			10   => '#FFC9C9',
    			// timing
    			3072 => '#98005D',
    			12   => '#FFB8E9',
    			// format
    			3584 => '#003804',
    			14   => '#00FB12',
    			// version
    			4096 => '#650098',
    			16   => '#E0B8FF',
    			// data
    			1024 => '#4A6000',
    			4    => '#ECF9BE',
    			// darkmodule
    			512  => '#080063',
    			// separator
    			8    => '#DDDDDD',
    			// quietzone
    			18   => '#DDDDDD',
    		],
    	]);
    	header('Content-type: image/png');
    	// print_r((new QRCode($options2))->render($data));die();
    	$qrOutputInterface = new QRCodeLogo($options, (new QRCode($options2))->getMatrix($data));
    	
    	echo $qrOutputInterface->dump(null, FCPATH.'/image.png');
    	die();
    
    Reviewed by crustamet at 2021-06-03 21:07
  • 2. Support for logo?

    Hello,

    Thank you for the well done QR Code generation!

    I see that there is a configuration option that supports a logo in the center of the QR Code, which has not yet been implemented. Is there a target time frame for this, or is there insufficient user interest?

    Best Regards,

    Edward

    Reviewed by EdwardCaulfield at 2020-09-25 11:25
  • 3. [Suggestion] Non square logos are stretching (not really a bug)

    Hello,

    In regards to #35 (where you did an EXCELLENT job - as in the full library as a whole), I have noticed that using non-square logos it's a bit hard to determine the number of squares that should be reserved in the matrix for a particular image using logoWidth and logoHeight in a way it doesn't stretch.

    Example given: I have a logo of 972x324px (3:1 width:height scale). Setting logoWidth = 30 and logoHeight = 10 (following the 3:1 WxH ratio of the logo), the resulting QR Code is "stretched" horizontally... :joy_cat:

    Reason: there's 1 extra "block" reserved by your lib at all edges (top, bottom, left, right) and the actual space the logo will occupy in the matrix is 28x8 (3.5:1).

    For it to work as expected, I had to set logoWidth = 32 (2 blocks extra at top and bottom = 30 for the logo image) and logoHeight = 12 (2 blocks extra at left and right = 10 for the logo), and boom! The logo is now perfectly fit and the ratio 3:1 is kept.

    My suggestion is logoWidth and logoHeight had 2 "automatically added" internally in the lib, so the definition of these values would be much more intuitive (W 30 H 10 = ratio kept).

    Reviewed by renatofrota at 2020-11-22 05:26
  • 4. Rounded Corners Pull Request

    I've written a custom output class to generate rounded corners, like this:

    Screen Shot 2022-05-25 at 14 00 15

    It works fine for my use case, but would you be interested in a pull request? If you are then I'll clean it up, write some tests, etc.

    Also it currently only outputs to SVG. Which is all I need myself, I wouldn't want to write the code to do rounded corners as a bitmap...

    Reviewed by abhibeckert at 2022-05-25 04:07
  • 5. Fix PHP 8.1 deprecation

    Hi,

    This fixes a minor deprecation in 4.3 branch for PHP 8.1.

    Without this here is the risen deprecation:

    Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated

    Reviewed by jmsche at 2022-01-20 16:31
  • 6. Works locally but not on server

    Hi,

    Thanks for the great lib :)

    Everything works fine locally but doesn't seem to work on my server (Ubuntu 18.4 on Digital Ocean).

    I have tried checking and installing the php7.3 extension one by one but still no success.

    Can you help with a lead?

    Reviewed by charlesmudy at 2019-12-14 19:01
  • 7. Basic (novice) question: running examples

    I have done: step 1: get composer step 2: composer install (created all dirs etc)

    What do I do now to run the example(s) in the tests directory?

    Could someone provide a simple index.php that would use the package, and is located in the root dir of my server? The package is installed in php-qrcode-master directory, under the root dir.

    Thanks very much.

    Reviewed by uhaile at 2018-07-20 09:06
  • 8. Upgrading from 3.4.0 to 3.4.1 breaks PHP 7.3

    Seems that the library upgrades internally to the php-settings-container v2.1.2 and this is not compatible with PHP 7.3. Getting an exception with the following content:

    syntax error, unexpected 'SettingsContainerInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)

    I would have prefered if the version number would have gone up to 3.5.0 or even 4.0 since some of the loaded libs are clearly not compatible anymore. Wa snow downgrading on our environment.

    Reviewed by roberthenniger at 2021-09-09 08:27
  • 9. About php5 branch

    First off, thank you very much for this library!

    I'm working with the Drupal 8 GA Login module and we're hoping to use this library. We have the 2.x branch of this library working well, but had a user run into a problem with the minimum php version being 7.x.

    Since Drupal 8 still officially supports PHP 5.6 I think it's in the GA_Login module's best interest to do the same, so I'm curious what you can tell me about the last version of this library that supported php5.6.

    It looks like to me that we could use version 1.1.0 from packagist and support php5.6. Does that sound right to you?

    If 1.1.0 branch would work for us, do you think there is any reason why we (GA_Login module) shouldn't use it? Is it significantly behind in features we might need, or insecure in some way?

    Thanks again for dropping by the ga_login issue queue and for the great library!

    Reviewed by daggerhart at 2018-01-19 02:44
  • 10. SVG output lines between paths

    Hi,

    I've noticed that outputting the QR code as SVG generates SVG with lines that look like borders on some squares. I haven't managed to figure out what exactly those lines are, stroke, outline or just misalignment of paths, it seems like they are transparent. Here is a screenshot of SVG versus the PNG output so its easier to notice what I'm talking about.

    SVG QR code

    PNG QR code

    My QR options are: _ 'version' => 6, 'eccLevel' => QRCode::ECC_L, 'outputType' => QRCode::OUTPUT_MARKUP_SVG, 'imageBase64' => false _

    Can you try recreating the issue and looking into it please, maybe I'm doing something wrong. Thank you ahead!

    Reviewed by ipetak at 2021-01-05 20:27
  • 11. Generate QR from raw binary data

    I'm looking to generate QR codes from raw binary data rather than text, as it makes for much more compact codes - for example a timestamp value (from time()) as text is at least 10 bytes, but as raw data is only 4 (pack('L', time())), but this QR code renderer dies when given raw data like that. It it possible to disable character set semantics and accept raw binary input with this package?

    Reviewed by Synchro at 2019-12-04 11:38
EMR and PM Software written in PHP7

ReadMe IMWEMR is EMR/PM software, along with integrated iascemr (surgerycenter) and optical, repo is ready and preconfigured for subdomain http://demo

Dec 4, 2021
Magento2 + Varnish + PHP7 + Redis + SSL (cluster ready)

Docker Magento2: Varnish + PHP7 + Redis + SSL cluster ready docker-compose infrastructure Infrastructure overview Container 1: MariaDB Container 2: Re

May 7, 2022
xhprof for PHP7

xhprof for PHP7 XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection c

Aug 12, 2022
Modello base con tutto il docker configurato per php7.4, mariadb, vue3, apache...con esempi di component e chiamate rest interne

Applicazione base per utilizzare laravel con docker, php7.4, apache, mariadb10, vue3 Semplice installazione corredate di rotte web e api di base, 3 co

Jul 14, 2022
Contracts for Rule Doc Generator. Useful for production code with minimum dependencies.

Rule Doc Generator Contracts Contracts for Rule Doc Generator. Useful for production code with minimum dependencies. Install composer require symplify

Feb 1, 2022
Algerian code generator for invoices, quotes or any commercial documents

Algerian invoice code generator The library is useful to generate code for invoices, quotes or any commercial transaction document. Goal Is to provide

Jul 19, 2021
Magento 2 Code Generator

Magento 2 Code Generator Created by Orba Inspired by https://github.com/staempfli/magento2-code-generator Purpose In day-to-day Magento 2 development

Jul 15, 2022
Code generator for Magento 2
Code generator for Magento 2

Magento 2 Code Generator Tool Installation Option1: Downloading .phar wget https://github.com/staempfli/magento2-code-generator/releases/download/<ver

Jul 13, 2022
Runtime Code Generator like Lombok for PocketMine-MP
Runtime Code Generator like Lombok for PocketMine-MP

PlumbokPM Runtime Code Generator like Lombok for PocketMine-MP. Code generation starts when additional autoloader detects class uses PlumbokPM annotat

Apr 18, 2022
Result of our code-along meetup writing PHP 8.1 code

PHP 8.1 Demo Code This code demonstrates various PHP 8.0 and 8.1 features in a realistic, functional (but incomplete) codebase. The code is part of so

Nov 14, 2021
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

Aug 8, 2022
Free ZIP Code API - Free Access to Worldwide Postal Code Data

About Zipcodebase - Free Zip Code API Zipcodebase is a zip code API that was founded in 2019 to solve common issues with postal code data. As we have

Jul 27, 2022
Dead Code Detector (DCD) for PHP code.

This project is no longer maintained and its repository is only kept for archival purposes. PHP Dead Code Detector (PHPDCD) phpdcd is a Dead Code Dete

Jul 6, 2022
Preload your sweet sweet code to opcache with a composer command, making your code faster to run.

Composer Preload Preload your sweet sweet code to opcache with a composer command, making your code run faster. Composer Preload is a composer plugin

Jul 11, 2022
The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

Aug 9, 2022
Webman quickly creates a verification code tool similar to Google verification code
Webman quickly creates a verification code tool similar to Google verification code

webman-captcha-grid webman quickly creates a verification code tool similar to Google verification code webman 快速创建一个类似于 Google 点图验证码的本地验证码扩展 介绍 webma

Apr 30, 2022
GPT-3 powered business idea generator

The idea (lol) is to give you inspiration to make something cool, if you lack inspiration right now. Many ideas might not be perfect but they might give you the spark to start thinking to get to a really good idea further on.

Feb 9, 2022
64 bit ID Generator

Particle Language: PHP 64bits int Time Based ID Generator Uncoordinated For high availability within and across data centers, machines generating ids

Jul 26, 2022
PHP Sitemap Generator

This class can be used to generate sitemaps and notify updates to search engines.

May 30, 2022