A QR Code generator for PHP7.4+

Overview

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

Comments
  • QRCode image with logo and colors not working

    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();
    
    opened by crustamet 18
  • Support for logo?

    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

    opened by EdwardCaulfield 15
  • [Suggestion] Non square logos are stretching (not really a bug)

    [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).

    opened by renatofrota 10
  • Rounded Corners Pull Request

    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...

    opened by abhibeckert 9
  • Fix PHP 8.1 deprecation

    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

    opened by jmsche 9
  • Works locally but not on server

    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?

    opened by charlesmudy 8
  • Basic (novice) question: running examples

    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.

    opened by uhaile 7
  • Upgrading from 3.4.0 to 3.4.1 breaks PHP 7.3

    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.

    opened by roberthenniger 6
  • About php5 branch

    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!

    opened by daggerhart 6
  • SVG output lines between paths

    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!

    help wanted 
    opened by ipetak 5
  • Generate QR from raw binary data

    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?

    opened by Synchro 5
Releases(4.3.4)
  • 4.3.4(Jul 25, 2022)

    • Fixed QRCode::isByte(): string "0" fails with empty()
    • Require chillerlan/php-settings-container: ^2.1.4 to fix a PHP 8.1 deprecation warning. See https://github.com/chillerlan/php-settings-container/discussions/2
    • CI updates
    Source code(tar.gz)
    Source code(zip)
  • 4.3.3(Feb 28, 2022)

  • 4.3.2(Nov 18, 2021)

  • 3.4.1(Sep 9, 2021)

    • PHP8 compatibility

    This is a fire-and-forget release! Reminder that PHP 7.2 is already EOL and 7.3 is EOL by December 2021. Fix your composer.json requirements now!

    Source code(tar.gz)
    Source code(zip)
  • 4.3.1(Jul 19, 2021)

  • 4.3.0(Nov 19, 2020)

    :sparkles: One Million Edition :sparkles:

    New features:

    • support for logos: QRMatrix::setLogoSpace() (example), added constant QRMatrix::M_LOGO (#52)
    • allowed coloring the dot of the finder patterns individually via the new constant QRMatrix::M_FINDER_DOT (#52)
    • allowed returning the image resource (resource , GdImage, Imagick, FPDF) from QROutputInterface::dump() via QROptions::$returnResource
    • allowed returning base64 encoded data URIs for SVG and FPDF output

    Fixes & cleanup:

    • fixed a bug that could cause unexpected "code length overflow" exceptions for version 33 QR Codes
    • stopped tampering with mb_internal_encoding() as it had no effect here anyways
    • check for ext-gd and ext-imagick when initializing the respective output modules
    • migrated phpunit.xml to support the new format
    • moved CI completely to GH Actions via shivammathur/setup-php - sorry Travis! :(
    • moved documentation to the wiki
    Source code(tar.gz)
    Source code(zip)
  • 3.4.0(Nov 19, 2020)

    :sparkles: One Million Edition :sparkles:

    New features:

    • support for logos: QRMatrix::setLogoSpace() (example), added constant QRMatrix::M_LOGO (#52)
    • allowed coloring the dot of the finder patterns individually via the new constant QRMatrix::M_FINDER_DOT (#52)
    • allowed returning the image resource (resource , GdImage, Imagick, FPDF) from QROutputInterface::dump() via QROptions::$returnResource
    • allowed returning base64 encoded data URIs for SVG and FPDF output
      • this change may break backwards compatibility for these output modes - to fix this, set QROptions::$imageBase64 to false.

    Fixes & cleanup:

    • fixed a bug that could cause unexpected "code length overflow" exceptions for version 33 QR Codes
    • stopped tampering with mb_internal_encoding() as it had no effect here anyways
    • check for ext-gd and ext-imagick when initializing the respective output modules

    (deleted & re-released as the previous 3.4.0 tag pointed to the 4.x branch. sorry for any inconvenience, i am dumb.)

    Source code(tar.gz)
    Source code(zip)
  • 4.2.0(Oct 7, 2020)

  • 4.1.0(Jun 4, 2020)

  • 3.3.0(Jun 4, 2020)

    • Added PDF support via FPDF
    • Made ext-gd and ext-json optional (removed from composer.json). Please note that ext-gd is still necessary for the default output method that is png.
    Source code(tar.gz)
    Source code(zip)
  • 4.0.1(Apr 12, 2020)

    • fixed a bug that could result in unreadable QR codes in case when mask pattern 001, 010 and 100 were used (variables $x and $y were swapped) - see #45 for more information
    • improved mask pattern generation
    Source code(tar.gz)
    Source code(zip)
  • 3.2.3(Apr 12, 2020)

    • fixed a bug that could result in unreadable QR codes in case when mask pattern 001, 010 and 100 were used (variables $x and $y were swapped) - see #45 for more information
    • improved mask pattern generation
    Source code(tar.gz)
    Source code(zip)
  • 2.0.8(Apr 12, 2020)

    • fixed a bug that could result in unreadable QR codes in case when mask pattern 001, 010 and 100 were used (variables $x and $y were swapped) - see #45 for more information
    • improved mask pattern generation
    Source code(tar.gz)
    Source code(zip)
  • 1.0.9(Apr 12, 2020)

    • fixed a bug that could result in unreadable QR codes in case when mask pattern 001, 010 and 100 were used (variables $x and $y were swapped) - see #45 for more information
    • improved mask pattern generation
    Source code(tar.gz)
    Source code(zip)
  • 4.0.0(Apr 6, 2020)

    Source code(tar.gz)
    Source code(zip)
  • 3.2.2(Apr 5, 2020)

    • fixed a bug that could result in unreadable QR codes in case when mask pattern 2 and 3 were used (variables $x and $y were flipped)
    • improved mask pattern generation
    Source code(tar.gz)
    Source code(zip)
  • 2.0.7(Apr 5, 2020)

    • fixed a bug that could result in unreadable QR codes in case when mask pattern 2 and 3 were used (variables $x and $y were flipped)
    • improved mask pattern generation
    Source code(tar.gz)
    Source code(zip)
  • 3.2.1(Feb 19, 2020)

  • 3.2.0(Dec 4, 2019)

  • 3.1.1(Aug 9, 2019)

    Many commits, few changes :octocat:

    • dependency updates
      • added ext-gd to composer.json as it is required for the default settings
      • PHPUnit 8.3
      • added PHP 7.4 snapshot to .travis.yml
    • cleanup:
      • QRImage::$background removed as it was unnecessary (now local in QRImage::dump())
      • use function imports
      • sprintf() for several messages and other output
      • format of QRMatrix::formatPattern and QRMatrix::versionPattern changed from hex to binary for better comprehensibility
      • QROptionsTrait::__set() removed in favor of SettingsContainerInterface setters set_versionMin(int $version) and set_versionMax(int $version)
      • additional coverage tests
    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Apr 19, 2019)

    • SVG images now use viewBox instead of width and height to scale. A new property $svgViewBoxSize has been added to QROptions, $scale has no effect. QRMarkup has a new property $svgHeader that you can overwrite when inheriting that class. This change may cause unexpected scaling results if you're using SVG output. See #30 and https://github.com/chillerlan/php-qrcode/commit/090bbeb0f1f3ab0e4e856a9ab3c118d8b09a440d
    • PHPUnit has been updated to v8.0
    • minor readme, .gitignore & test fixes
    Source code(tar.gz)
    Source code(zip)
  • 3.0.3(Dec 20, 2018)

    • values passed to a QROptions object will now always be checked/clamped (e.g. when passed as individual value, not only through the constructor)
    • PHPUnit bumped to 7.5
    • cleanup
    • PHP 5 IS KILL. LET IT DIE.
    Source code(tar.gz)
    Source code(zip)
  • 3.0.2(Nov 22, 2018)

    • moved configuration checks over to QROptionsTrait
    • added QROptionsTest
    • the original value of mb_internal_encoding() will now be restored on QRCode::__destruct()
    • PHPUnit version bumped to 7.4, PHP 7.3 added to the Travis CI test matrix
    • several doc fixes
    Source code(tar.gz)
    Source code(zip)
  • 3.0.1(Oct 1, 2018)

    • moved Number::CHAR_MAP and AlphaNum::CHAR_MAP to QRDataInterface::NUMBER_CHAR_MAP and QRDataInterface::ALPHANUM_CHAR_MAP respectively. (quick, as long as v3.0 is warm... not going to bother about this "breaking" change as these constants shouldn't be used anywhere except in QRCode)
    Source code(tar.gz)
    Source code(zip)
  • 3.0.0(Oct 1, 2018)

    • dropped support for PHP < 7.2
      • use v2.0.6 in case you still need 7.0 support
      • or v1.0.8 for PHP5. Wait no. Please let PHP5 die! Stop contributing to technological debt! :ghost:
    • reduced overhead by minimizing dependencies
    • added QRCode::OUTPUT_IMAGICK via QRImagick. Inherit & overwrite QRImagick::drawImage(Imagick $imagick):string for your own ImageMagick output class.
    • added optional $file parameter to QROutputInterface::dump(string $file = null) which will be used before QROptions::$cachefile.
    • removed QRCode::setOptions() - options init now happens in QROptions. See SettingsContainerAbstract for more info.
    • cleanup & fixes™
    Source code(tar.gz)
    Source code(zip)
  • 2.0.6(Mar 28, 2018)

  • 2.0.5(Mar 26, 2018)

  • 2.0.4(Mar 10, 2018)

    • fixed
      • impossible clamp - https://github.com/chillerlan/php-qrcode/issues/12
      • ridiculous code - https://github.com/chillerlan/php-qrcode/pull/14
    • added
    Source code(tar.gz)
    Source code(zip)
  • 2.0.3(Jan 23, 2018)

  • 2.0.2(Jan 21, 2018)

Owner
chillerlan
smiley.codes
chillerlan
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

null 1 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

Fabrizio Balliano 332 Dec 30, 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

XinHui Long 908 Dec 27, 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

null 0 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

null 19 Dec 22, 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

Hippone Consulting 7 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

null 74 Nov 14, 2022
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

Stämpfli AG 254 Dec 5, 2022
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

OctoPush 4 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

azPHP 2 Nov 14, 2021
⚗️ 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

Nuno Maduro 4.4k Jan 4, 2023
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

SaaS Industries 2 Nov 26, 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

Sebastian Bergmann 406 Dec 30, 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

Ayesh Karunaratne 197 Dec 6, 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

QOSSMIC GmbH 389 Nov 24, 2022
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

听风吹雨 6 Dec 5, 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.

levelsio 17 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

Silviu | ซีลวิอุ 130 Jul 26, 2022