Convert Figma logo to code with AI

endroid logoqr-code

QR Code Generator

4,420
726
4,420
8

Top Related Projects

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

3,701

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.

High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.

13,583

Cross-browser QRCode generator for javascript

QR Code Generator implementation in JavaScript, Java and more.

A fast and compact QR Code encoding library

Quick Overview

Endroid/qr-code is a PHP library for generating QR codes. It provides a simple and flexible way to create QR codes with various options, including custom colors, sizes, and error correction levels. The library is designed to be easy to use while offering advanced customization capabilities.

Pros

  • Easy to use with a straightforward API
  • Supports various output formats (PNG, SVG, EPS)
  • Highly customizable with options for colors, size, and error correction
  • Actively maintained and compatible with modern PHP versions

Cons

  • Limited to QR code generation (doesn't support scanning or decoding)
  • Requires GD or Imagick extension for image manipulation
  • May have performance limitations for generating large numbers of QR codes

Code Examples

Creating a basic QR code:

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('https://www.example.com');
header('Content-Type: ' . $qrCode->getContentType());
echo $qrCode->writeString();

Customizing QR code appearance:

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Color\Color;

$qrCode = new QrCode('Custom QR Code');
$qrCode->setSize(300);
$qrCode->setForegroundColor(new Color(0, 0, 255));
$qrCode->setBackgroundColor(new Color(255, 255, 0));
$qrCode->writeFile('custom_qr_code.png');

Generating a QR code with a logo:

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Logo\Logo;

$qrCode = new QrCode('QR Code with Logo');
$logo = Logo::create('path/to/logo.png')
    ->setResizeToWidth(50);
$qrCode->setLogo($logo);
$qrCode->writeFile('qr_code_with_logo.png');

Getting Started

  1. Install the library using Composer:
composer require endroid/qr-code
  1. Create a simple PHP script to generate a QR code:
<?php

require 'vendor/autoload.php';

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;

$qrCode = new QrCode('Hello, World!');
$writer = new PngWriter();

$result = $writer->write($qrCode);

header('Content-Type: ' . $result->getMimeType());
echo $result->getString();
  1. Run the script in your web server or from the command line to generate and display the QR code.

Competitor Comparisons

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

Pros of php-qrcode

  • More extensive customization options for QR code generation
  • Better performance for generating large numbers of QR codes
  • Supports a wider range of output formats (PNG, GIF, JPG, SVG, etc.)

Cons of php-qrcode

  • Steeper learning curve due to more complex API
  • Requires more setup and configuration for basic usage
  • Larger codebase, which may impact project size

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');

qr-code:

$writer = new PngWriter();
$qrCode = QrCode::create('https://example.com')
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(ErrorCorrectionLevel::Low)
    ->setSize(300);
$result = $writer->write($qrCode);

Both libraries offer robust QR code generation capabilities, but php-qrcode provides more advanced features and customization options at the cost of increased complexity. qr-code, on the other hand, offers a simpler API for basic QR code generation tasks, making it more accessible for beginners or projects with straightforward requirements.

3,701

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.

Pros of jsQR

  • Written in JavaScript, making it ideal for web-based applications
  • Can decode QR codes directly from image data or video streams
  • Lightweight and easy to integrate into existing web projects

Cons of jsQR

  • Limited to QR code generation and scanning
  • May have performance limitations for large-scale or high-speed applications
  • Less actively maintained compared to qr-code

Code Comparison

qr-code (PHP):

$writer = new PngWriter();
$qrCode = QrCode::create('https://example.com')
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
    ->setSize(300)
    ->setMargin(10)
    ->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
    ->setForegroundColor(new Color(0, 0, 0))
    ->setBackgroundColor(new Color(255, 255, 255));

jsQR (JavaScript):

const code = jsQR(imageData.data, imageData.width, imageData.height);
if (code) {
  console.log("Found QR code", code.data);
}

The code examples demonstrate the different approaches: qr-code focuses on QR code generation with extensive customization options, while jsQR is primarily used for QR code scanning and decoding from image data.

High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.

Pros of QR-Code-generator

  • Supports multiple programming languages (C++, Java, JavaScript, Python)
  • Provides more low-level control and customization options
  • Offers better performance for generating large numbers of QR codes

Cons of QR-Code-generator

  • Less user-friendly for beginners or simple use cases
  • Requires more manual configuration and setup
  • Limited built-in styling options compared to qr-code

Code Comparison

QR-Code-generator (Python):

import qrcode
qr = qrcode.QrCode(version=1, error_correction=qrcode.ErrorCorrectionLevel.L)
qr.add_data("Hello, World!")
qr.make(fit=True)

qr-code (PHP):

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('Hello, World!');
$qrCode->setSize(300);
$qrCode->setMargin(10);

QR-Code-generator focuses on providing a flexible, low-level API for generating QR codes across multiple languages, making it suitable for more complex projects or when performance is crucial. On the other hand, qr-code offers a more user-friendly approach with built-in styling options, making it easier to use for simple QR code generation tasks, especially in PHP-based projects.

13,583

Cross-browser QRCode generator for javascript

Pros of qrcodejs

  • Pure JavaScript implementation, no server-side processing required
  • Lightweight and easy to integrate into web applications
  • Supports various output formats (canvas, table, SVG)

Cons of qrcodejs

  • Limited customization options compared to qr-code
  • Less actively maintained (last update in 2020)
  • Lacks advanced features like error correction level adjustment

Code Comparison

qrcodejs:

var qrcode = new QRCode("qrcode", {
    text: "http://example.com",
    width: 128,
    height: 128,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.H
});

qr-code:

use Endroid\QrCode\QrCode;

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

Summary

qrcodejs is a client-side JavaScript library for generating QR codes, making it ideal for web applications that require quick and simple QR code generation. It's lightweight and easy to use but lacks some advanced features and customization options.

qr-code, on the other hand, is a PHP library that offers more robust features and customization options. It supports server-side generation and provides additional functionality like error correction level adjustment and various output formats.

Choose qrcodejs for simple, client-side QR code generation in web applications, and qr-code for more advanced, server-side QR code generation with greater customization options.

QR Code Generator implementation in JavaScript, Java and more.

Pros of qrcode-generator

  • Supports multiple programming languages (JavaScript, Java, C++, etc.)
  • Lightweight and has minimal dependencies
  • Offers more customization options for QR code generation

Cons of qrcode-generator

  • Less actively maintained compared to qr-code
  • Documentation is not as comprehensive
  • Fewer built-in features for image manipulation and output formats

Code Comparison

qrcode-generator (JavaScript):

var qr = qrcode(4, 'L');
qr.addData('Hello, World!');
qr.make();
var imgTag = qr.createImgTag(4);

qr-code (PHP):

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('Hello, World!');
$qrCode->setSize(300);
$qrCode->setMargin(10);
$qrCode->writeFile('qrcode.png');

Both libraries offer straightforward ways to generate QR codes, but qr-code provides a more object-oriented approach with additional built-in options for customization and output. qrcode-generator's implementation is more lightweight and can be easily integrated into various programming environments.

A fast and compact QR Code encoding library

Pros of libqrencode

  • Written in C, offering potentially better performance and lower-level system integration
  • Supports a wider range of QR code versions and error correction levels
  • Can be used as a library in various programming languages through bindings

Cons of libqrencode

  • Requires compilation and may be more complex to set up for some users
  • Less user-friendly for developers who prefer high-level language implementations
  • May require additional steps for integration in web-based projects

Code Comparison

libqrencode (C):

QRcode *qrcode = QRcode_encodeString("Hello, World!", 0, QR_ECLEVEL_L, QR_MODE_8, 1);

qr-code (PHP):

$writer = new PngWriter();
$qrCode = QrCode::create('Hello, World!')
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow());
$result = $writer->write($qrCode);

Summary

libqrencode is a powerful C library for generating QR codes, offering high performance and extensive customization options. It's suitable for low-level integrations and supports multiple programming languages through bindings. However, it may require more setup and technical knowledge compared to qr-code, which provides a more user-friendly PHP implementation for web developers. The choice between the two depends on the specific project requirements, programming language preferences, and desired level of control over the QR code generation process.

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

QR Code

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License

This library helps you generate QR codes in a jiffy. Makes use of bacon/bacon-qr-code to generate the matrix and khanamiryan/qrcode-detector-decoder for validating generated QR codes. Further extended with Twig extensions, generation routes, a factory and a Symfony bundle for easy installation and configuration. Different writers are provided to generate the QR code as PNG, SVG, EPS or in binary format.

Sponsored by

Blackfire.io

Installation

Use Composer to install the library. Also make sure you have enabled and configured the GD extension if you want to generate images.

 composer require endroid/qr-code

Usage: using the builder

use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\Label\LabelAlignment;
use Endroid\QrCode\Label\Font\NotoSans;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;

$result = Builder::create()
    ->writer(new PngWriter())
    ->writerOptions([])
    ->data('Custom QR code contents')
    ->encoding(new Encoding('UTF-8'))
    ->errorCorrectionLevel(ErrorCorrectionLevel::High)
    ->size(300)
    ->margin(10)
    ->roundBlockSizeMode(RoundBlockSizeMode::Margin)
    ->logoPath(__DIR__.'/assets/symfony.png')
    ->logoResizeToWidth(50)
    ->logoPunchoutBackground(true)
    ->labelText('This is the label')
    ->labelFont(new NotoSans(20))
    ->labelAlignment(LabelAlignment::Center)
    ->validateResult(false)
    ->build();

Usage: without using the builder

use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Label\Label;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\ValidationException;

$writer = new PngWriter();

// Create QR code
$qrCode = QrCode::create('Life is too short to be generating QR codes')
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(ErrorCorrectionLevel::Low)
    ->setSize(300)
    ->setMargin(10)
    ->setRoundBlockSizeMode(RoundBlockSizeMode::Margin)
    ->setForegroundColor(new Color(0, 0, 0))
    ->setBackgroundColor(new Color(255, 255, 255));

// Create generic logo
$logo = Logo::create(__DIR__.'/assets/symfony.png')
    ->setResizeToWidth(50)
    ->setPunchoutBackground(true)
;

// Create generic label
$label = Label::create('Label')
    ->setTextColor(new Color(255, 0, 0));

$result = $writer->write($qrCode, $logo, $label);

// Validate the result
$writer->validateResult($result, 'Life is too short to be generating QR codes');

Usage: working with results


// Directly output the QR code
header('Content-Type: '.$result->getMimeType());
echo $result->getString();

// Save it to a file
$result->saveToFile(__DIR__.'/qrcode.png');

// Generate a data URI to include image data inline (i.e. inside an <img> tag)
$dataUri = $result->getDataUri();

QR Code

Writer options

Some writers provide writer options. Each available writer option is can be found as a constant prefixed with WRITER_OPTION_ in the writer class.

  • PdfWriter
    • unit: unit of measurement (default: mm)
    • fpdf: PDF to place the image in (default: new PDF)
    • x: image offset (default: 0)
    • y: image offset (default: 0)
    • link: a URL or an identifier returned by AddLink().
  • PngWriter
    • compression_level: compression level (0-9, default: -1 = zlib default)
  • SvgWriter
    • block_id: id of the block element for external reference (default: block)
    • exclude_xml_declaration: exclude XML declaration (default: false)
    • exclude_svg_width_and_height: exclude width and height (default: false)
    • force_xlink_href: forces xlink namespace in case of compatibility issues (default: false)
    • compact: create using path element, otherwise use defs and use (default: true)
  • WebPWriter
    • quality: image quality (0-100, default: 80)

You can provide any writer options like this.

use Endroid\QrCode\Writer\SvgWriter;

$builder->writerOptions([
    SvgWriter::WRITER_OPTION_EXCLUDE_XML_DECLARATION => true
]);

Encoding

If you use a barcode scanner you can have some troubles while reading the generated QR codes. Depending on the encoding you chose you will have an extra amount of data corresponding to the ECI block. Some barcode scanner are not programmed to interpret this block of information. To ensure a maximum compatibility you can use the ISO-8859-1 encoding that is the default encoding used by barcode scanners (if your character set supports it, i.e. no Chinese characters are present).

Round block size mode

By default block sizes are rounded to guarantee sharp images and improve readability. However some other rounding variants are available.

  • margin (default): the size of the QR code is shrunk if necessary but the size of the final image remains unchanged due to additional margin being added.
  • enlarge: the size of the QR code and the final image are enlarged when rounding differences occur.
  • shrink: the size of the QR code and the final image are shrunk when rounding differences occur.
  • none: No rounding. This mode can be used when blocks don't need to be rounded to pixels (for instance SVG).

Readability

The readability of a QR code is primarily determined by the size, the input length, the error correction level and any possible logo over the image so you can tweak these parameters if you are looking for optimal results. You can also check $qrCode->getRoundBlockSize() value to see if block dimensions are rounded so that the image is more sharp and readable. Please note that rounding block size can result in additional padding to compensate for the rounding difference. And finally the encoding (default UTF-8 to support large character sets) can be set to ISO-8859-1 if possible to improve readability.

Validating the generated QR code

If you need to be extra sure the QR code you generated is readable and contains the exact data you requested you can enable the validation reader, which is disabled by default. You can do this either via the builder or directly on any writer that supports validation. See the examples above.

Please note that validation affects performance so only use it in case of problems.

Symfony integration

The endroid/qr-code-bundle integrates the QR code library in Symfony for an even better experience.

  • Configure your defaults (like image size, default writer etc.)
  • Support for multiple configurations and injection via aliases
  • Generate QR codes for defined configurations via URL like /qr-code//Hello
  • Generate QR codes or URLs directly from Twig using dedicated functions

Read the bundle documentation for more information.

Versioning

Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.

License

This bundle is under the MIT license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.