Convert Figma logo to code with AI

Bacon logoBaconQrCode

QR Code Generator for PHP

1,850
212
1,850
17

Top Related Projects

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

4,420

QR Code Generator

QR Code Generator implementation in JavaScript, Java and more.

13,583

Cross-browser QRCode generator for javascript

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

Quick Overview

BaconQrCode is a PHP library for generating QR codes. It provides a simple and flexible way to create QR codes in various formats, including SVG, PNG, and as raw binary data. The library supports different error correction levels and can handle various types of data input.

Pros

  • Easy to use with a straightforward API
  • Supports multiple output formats (SVG, PNG, raw binary)
  • Customizable error correction levels
  • Actively maintained and compatible with modern PHP versions

Cons

  • Limited to QR code generation (no scanning or decoding functionality)
  • Requires GD library for PNG output
  • May have performance limitations for generating large numbers of QR codes
  • Documentation could be more comprehensive

Code Examples

  1. Generate a simple QR code as SVG:
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;

$renderer = new ImageRenderer(
    new RendererStyle(400),
    new SvgImageBackEnd()
);
$writer = new Writer($renderer);
$svg = $writer->writeString('Hello, World!');
  1. Generate a QR code with custom error correction level:
use BaconQrCode\Encoder\Encoder;
use BaconQrCode\Common\ErrorCorrectionLevel;

$qrCode = Encoder::encode('https://example.com', ErrorCorrectionLevel::H);
  1. Generate a QR code as PNG:
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('https://example.com', 'qrcode.png');

Getting Started

  1. Install the library using Composer:

    composer require bacon/bacon-qr-code
    
  2. Generate a basic QR code:

    use BaconQrCode\Renderer\ImageRenderer;
    use BaconQrCode\Renderer\Image\SvgImageBackEnd;
    use BaconQrCode\Renderer\RendererStyle\RendererStyle;
    use BaconQrCode\Writer;
    
    $renderer = new ImageRenderer(
        new RendererStyle(400),
        new SvgImageBackEnd()
    );
    $writer = new Writer($renderer);
    $svg = $writer->writeString('Hello, World!');
    
    // Output the SVG
    header('Content-Type: image/svg+xml');
    echo $svg;
    

This example generates a QR code as an SVG image and outputs it directly to the browser.

Competitor Comparisons

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

Pros of php-qrcode

  • More extensive documentation and examples
  • Supports a wider range of output formats (PNG, GIF, JPG, SVG, etc.)
  • Actively maintained with frequent updates

Cons of php-qrcode

  • Larger codebase, potentially more complex to integrate
  • Requires PHP 7.4 or higher, which may limit compatibility with older systems

Code Comparison

BaconQrCode:

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

php-qrcode:

$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 php-qrcode provides more flexibility in terms of output formats and customization options. BaconQrCode has a simpler API and may be easier to integrate for basic use cases. The choice between the two depends on specific project requirements and the desired level of control over QR code generation.

4,420

QR Code Generator

Pros of qr-code

  • More actively maintained with frequent updates
  • Supports a wider range of output formats (PNG, SVG, EPS, PDF)
  • Offers additional features like logo insertion and styling options

Cons of qr-code

  • Larger package size due to additional dependencies
  • Slightly more complex API for basic usage
  • May have a steeper learning curve for beginners

Code Comparison

BaconQrCode:

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

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

qr-code:

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

$qrCode = QrCode::create('Hello World!')
    ->setSize(300)
    ->setMargin(10);
$writer = new PngWriter();
$result = $writer->write($qrCode);
$result->saveToFile('qrcode.png');

Both libraries offer straightforward ways to generate QR codes, but qr-code provides more flexibility in terms of customization and output options. BaconQrCode has a simpler API for basic usage, while qr-code offers more advanced features at the cost of slightly increased complexity.

QR Code Generator implementation in JavaScript, Java and more.

Pros of qrcode-generator

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

Cons of qrcode-generator

  • Less actively maintained compared to BaconQrCode
  • Fewer advanced features and customization options
  • Limited documentation and examples

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

qrcode-generator (JavaScript):

var qr = qrcode(4, 'L');
qr.addData('Hello World!');
qr.make();
var img = qr.createImgTag(4);
document.getElementById('qrcode').innerHTML = img;

Both libraries offer straightforward ways to generate QR codes, but BaconQrCode provides more advanced rendering options and customization. qrcode-generator is simpler to use but offers fewer features.

13,583

Cross-browser QRCode generator for javascript

Pros of qrcodejs

  • Lightweight and easy to use, with a simple JavaScript implementation
  • Supports various output formats, including SVG and Canvas
  • No external dependencies, making it ideal for client-side applications

Cons of qrcodejs

  • Limited customization options compared to BaconQrCode
  • Lacks support for more advanced QR code features and error correction levels
  • Not actively maintained, with the last update in 2014

Code Comparison

BaconQrCode (PHP):

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

qrcodejs (JavaScript):

var qrcode = new QRCode(document.getElementById("qrcode"), {
    text: "Hello World!",
    width: 128,
    height: 128,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.H
});

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, and more)
  • Provides extensive documentation and examples
  • Offers more advanced features like error correction level control

Cons of QR-Code-generator

  • Less actively maintained (last update was over a year ago)
  • Requires more manual setup and integration
  • May have a steeper learning curve for beginners

Code Comparison

BaconQrCode:

$renderer = new ImageRenderer(
    new RendererStyle(400),
    new ImagickImageBackEnd()
);

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

QR-Code-generator:

import qrcode

qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data('Hello World!')
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
img.save('qrcode.png')

Both libraries offer straightforward ways to generate QR codes, but QR-Code-generator provides more flexibility across multiple programming languages. BaconQrCode, being PHP-specific, offers a simpler integration for PHP projects. The choice between the two depends on the specific project requirements, programming language preferences, and the need for advanced features.

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 generator

PHP CI codecov Latest Stable Version Total Downloads License

Introduction

BaconQrCode is a port of QR code portion of the ZXing library. It currently only features the encoder part, but could later receive the decoder part as well.

As the Reed Solomon codec implementation of the ZXing library performs quite slow in PHP, it was exchanged with the implementation by Phil Karn.

Example usage

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

Available image renderer back ends

BaconQrCode comes with multiple back ends for rendering images. Currently included are the following:

  • ImagickImageBackEnd: renders raster images using the Imagick library
  • SvgImageBackEnd: renders SVG files using XMLWriter
  • EpsImageBackEnd: renders EPS files

GDLib Renderer

GD library has so many limitations, that GD support is not added as backend, but as separated renderer. Use GDLibRenderer instead of ImageRenderer. These are the limitations:

  • Does not support gradient.
  • Does not support any curves, so you QR code is always squared.

Example usage:

use BaconQrCode\Renderer\GDLibRenderer;
use BaconQrCode\Writer;

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