Convert Figma logo to code with AI

chillerlan logophp-qrcode

A PHP QR Code generator and reader with a user-friendly API.

1,936
288
1,936
7

Top Related Projects

4,378

QR Code Generator

An easy-to-use PHP QrCode generator with first-party support for Laravel.

QR Code Generator for PHP

QR Code Generator implementation in JavaScript, Java and more.

Quick Overview

chillerlan/php-qrcode is a PHP library for generating QR codes. It offers a flexible and feature-rich solution for creating QR codes in various formats, including PNG, GIF, and SVG. The library supports customization options and provides a simple API for easy integration into PHP projects.

Pros

  • Supports multiple output formats (PNG, GIF, SVG)
  • Highly customizable with various styling options
  • Easy to use with a simple API
  • Actively maintained and regularly updated

Cons

  • Requires PHP 7.4+ or 8.0+, which may not be available on all hosting environments
  • Large file size compared to some simpler QR code libraries
  • May be overkill for basic QR code generation needs

Code Examples

  1. Basic QR code generation:
use chillerlan\QRCode\QRCode;

$qrcode = new QRCode();
$image = $qrcode->render('https://example.com');
  1. Customizing QR code appearance:
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;

$options = new QROptions([
    'outputType' => QRCode::OUTPUT_IMAGE_PNG,
    'eccLevel' => QRCode::ECC_H,
    'scale' => 5,
    'imageBase64' => false,
]);

$qrcode = new QRCode($options);
$image = $qrcode->render('https://example.com');
  1. Generating SVG QR code:
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;

$options = new QROptions([
    'outputType' => QRCode::OUTPUT_MARKUP_SVG,
    'imageBase64' => false,
]);

$qrcode = new QRCode($options);
$svg = $qrcode->render('https://example.com');

Getting Started

  1. Install the library using Composer:
composer require chillerlan/php-qrcode
  1. Use the library in your PHP code:
<?php

require_once 'vendor/autoload.php';

use chillerlan\QRCode\QRCode;

$qrcode = new QRCode();
$image = $qrcode->render('https://example.com');

// Output the image
header('Content-Type: image/png');
echo $image;

This will generate a basic QR code for the URL "https://example.com" and output it as a PNG image.

Competitor Comparisons

4,378

QR Code Generator

Pros of qr-code

  • More extensive documentation and examples
  • Supports a wider range of output formats (e.g., SVG, EPS, PDF)
  • Offers additional features like logo embedding and rounded corners

Cons of qr-code

  • Slightly larger package size
  • May have a steeper learning curve for beginners due to more options

Code Comparison

qr-code:

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('https://example.com');
$qrCode->setSize(300);
$qrCode->setMargin(10);
$qrCode->writeFile('qrcode.png');

php-qrcode:

use chillerlan\QRCode\QRCode;

$qrCode = new QRCode();
$qrCode->render('https://example.com', 'qrcode.png');

Both libraries offer straightforward ways to generate QR codes, but qr-code provides more customization options out of the box. php-qrcode has a simpler API for basic usage, which might be preferable for quick implementations.

While qr-code offers more features and flexibility, php-qrcode focuses on simplicity and ease of use. The choice between the two depends on the specific requirements of your project and the level of customization needed.

An easy-to-use PHP QrCode generator with first-party support for Laravel.

Pros of simple-qrcode

  • Easier integration with Laravel framework
  • Built-in support for various image formats (PNG, EPS, SVG)
  • Simpler API for basic QR code generation

Cons of simple-qrcode

  • Less customization options for advanced use cases
  • Fewer encoding options compared to php-qrcode
  • Dependency on Laravel framework limits standalone usage

Code Comparison

simple-qrcode:

QrCode::size(300)->generate('Hello World!');

php-qrcode:

$qrcode = new QRCode(new QROptions([
    'version'    => 5,
    'outputType' => QRCode::OUTPUT_IMAGE_PNG,
    'eccLevel'   => QRCode::ECC_L,
]));
$qrcode->render('Hello World!');

The simple-qrcode example demonstrates its simpler API for basic QR code generation, while the php-qrcode example shows more granular control over QR code options.

simple-qrcode is more suitable for Laravel projects requiring quick and easy QR code generation, while php-qrcode offers more flexibility and customization options for standalone PHP applications or advanced use cases.

QR Code Generator for PHP

Pros of BaconQrCode

  • More comprehensive documentation and examples
  • Supports a wider range of output formats (SVG, EPS, PDF)
  • Better integration with other libraries and frameworks

Cons of BaconQrCode

  • Slightly more complex API, which may require a steeper learning curve
  • Less frequent updates and maintenance compared to php-qrcode

Code Comparison

BaconQrCode:

use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;

$renderer = new ImageRenderer(
    new RendererStyle(400),
    new ImagickImageBackEnd()
);
$writer = new Writer($renderer);
$writer->writeFile('Hello World!', 'qrcode.png');

php-qrcode:

use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;

$options = new QROptions([
    'outputType' => QRCode::OUTPUT_IMAGE_PNG,
    'eccLevel' => QRCode::ECC_L,
]);
$qrcode = new QRCode($options);
$qrcode->render('Hello World!', 'qrcode.png');

Both libraries offer similar functionality for generating QR codes, but BaconQrCode provides more flexibility in terms of output formats and rendering options. php-qrcode, on the other hand, has a simpler API and is easier to use for basic QR code generation tasks. The choice between the two depends on the specific requirements of your project and your familiarity with the libraries.

QR Code Generator implementation in JavaScript, Java and more.

Pros of qrcode-generator

  • Multi-language support: Implementations in JavaScript, Java, and other languages
  • Lightweight and simple to use
  • Generates QR codes in various output formats (Canvas, SVG, Table)

Cons of qrcode-generator

  • Less actively maintained compared to php-qrcode
  • Fewer advanced features and customization options
  • Limited documentation and examples

Code Comparison

php-qrcode:

$qrcode = new QRCode(new QROptions([
    'version'    => 5,
    'outputType' => QRCode::OUTPUT_MARKUP_SVG,
    'eccLevel'   => QRCode::ECC_L,
]));
$qrcode->render('https://example.com');

qrcode-generator (JavaScript):

var qr = qrcode(0, 'L');
qr.addData('https://example.com');
qr.make();
var svg = qr.createSvgTag();

Both libraries offer straightforward ways to generate QR codes, but php-qrcode provides more configuration options out of the box. qrcode-generator's simplicity may be preferred for basic use cases, while php-qrcode offers more flexibility for advanced requirements.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

chillerlan/php-qrcode

A PHP QR Code generator based on the implementation by Kazuhiko Arase, namespaced, cleaned up, improved and other stuff.
It also features a QR Code reader based on a PHP port of the ZXing library.

Attention: there is now also a javascript port on NPM: @chillerlan/qrcode.

PHP Version Support Packagist version Continuous Integration CodeCov Codacy Packagist downloads Documentation

Overview

Features

  • Creation of Model 2 QR Codes, Version 1 to 40
  • ECC Levels L/M/Q/H supported
  • Mixed mode support (encoding modes can be combined within a QR symbol). Supported modes:
  • Flexible, easily extensible output modules, built-in support for the following output formats:
  • QR Code reader (via GD and ImageMagick)

Requirements

For the QR Code reader, either ext-gd or ext-imagick is required!

Documentation

Important: Please use the examples from the branch that matches your installed php-qrcode version ( v4.x, v5.x, dev-main )!

Installation with composer

See the installation guide for more info!

Terminal

composer require chillerlan/php-qrcode

composer.json

{
	"require": {
		"php": "^8.2",
		"chillerlan/php-qrcode": "dev-main#<commit_hash>"
	}
}

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

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" />';

Wait, what was that? Please again, slower! See Advanced usage in the manual. Also, have a look in the examples folder for some more usage examples.

QR codes are awesome!

Reading QR Codes

Using the built-in QR Code reader is pretty straight-forward:

// it's generally a good idea to wrap the reader in a try/catch block because it WILL throw eventually
try{
	$result = (new QRCode)->readFromFile('path/to/file.png'); // -> DecoderResult

	// you can now use the result instance...
	$content = $result->data;
	$matrix  = $result->getMatrix(); // -> QRMatrix

	// ...or simply cast it to string to get the content:
	$content = (string)$result;
}
catch(Throwable $e){
	// oopsies!
}

Shameless advertising

Hi, please check out some of 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

Trademark Notice

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