PHP Classes

How to Use a PHP QR Code Generator with Logo to Brand the Outputted Image Using the Package HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel: Generate QR code images in several formats

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-07-06 (15 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
heroqr 2.0.1Custom (specified...8.2Algorithms, Graphics, Tools, PHP 8
Description 

Author

This package can generate QR code images in several formats.

It can take a string of data to encode and output an image of the QR code or save to a file in one of several formats supported by the package.

Currently, it can:

- Output in formats like PNG, SVG, PDF, WebP, GIF, etc..

- Style the generated QR code foreground and background colors, have a quiet zone margin, etc.

- Brand the output image by overlaying a logo image, adding text labels, and using custom fonts

- Reliable QR code generation with error correction levels (L, M, Q, H) to be able to scan the code even when it is partially damaged

- Validation of QR code data that uses formats like URL, text, email, etc..

- Provides a service class to use in Laravel applications

Innovation Award
PHP Programming Innovation award nominee
August 2025
Number 6
Many applications need to generate QR Codes to encode data that application users can scan using the camera of their mobile phones.

This package provides a pure PHP solution to generate QR codes from any type of data in a way that can be customized with brand elements like logo images and text messages.

Manuel Lemos
Picture of Amirreza Ebrahimi
  Performance   Level  
Name: Amirreza Ebrahimi is available for providing paid consulting. Contact Amirreza Ebrahimi .
Classes: 2 packages by
Country: Iran Iran
Age: 24
All time rank: Not yet ranked
Week rank: Not yet ranked
Innovation award
Innovation award
Nominee: 2x

Instructions

Install with Composer:

composer require amirezaeb/heroqr

Basic usage (simplified):

require 'vendor/autoload.php';

use HeroQR\HeroQR;

(new HeroQR())
    ->data('https://example.com')
    ->format('png')      // png|svg|pdf
    ->size(512)          // px for raster, mm for PDF
    ->margin(2)
    ->logo(__DIR__.'/logo.png')
    ->save(__DIR__.'/qr-example.png');

You can learn more about using this page by looking at the documentation and examples in the README file.

Documentation

HeroQR - QR Code Library for PHP

<p align="center">

<a href="https://packagist.org/packages/amirezaeb/heroqr"><img alt="Latest Version" src="https://img.shields.io/packagist/v/amirezaeb/heroqr?style=for-the-badge"></a>
<a href="https://packagist.org/packages/amirezaeb/heroqr"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/amirezaeb/heroqr?style=for-the-badge&color=blue"></a>
<a href="https://github.com/AmirezaEb/HeroQR/actions/workflows/CI.yml"><img alt="Tests" src="https://img.shields.io/github/actions/workflow/status/AmirezaEb/HeroQR/CI.yml?style=for-the-badge&label=Tests&logo=github"></a>
<a href="https://packagist.org/packages/amirezaeb/heroqr"><img alt="PHP Version" src="https://img.shields.io/packagist/php-v/amirezaeb/heroqr?style=for-the-badge&color=violet"></a>
<a href="https://github.com/AmirezaEb/HeroQR/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/packagist/l/amirezaeb/heroqr?style=for-the-badge&color=orange"></a>

</p>

HeroQR is a PHP library for generating and customizing QR codes with full control over styling and multi-format output, while remaining ISO/IEC 18004 compliant.

Table of Contents

Features

  • Customization - Logo embedding with size control - Full color control (RGB/RGBA with transparency) - Custom labels with alignment, styling, and spacing - Automatic layout optimization for readability
  • Geometric Styling - Custom module shapes - Custom corner markers and cursors - Multiple predefined design styles (S, M, C sets) - SVG and PNG support for advanced rendering
  • Data Support - Generate QR codes for URLs, text, emails, vCards, WiFi, and more - Support for UTF-8 / UTF-16 / Base64 encoding
  • Validation - Built-in validation for URLs, emails, phones, IPs, and WiFi credentials
  • Export Formats - PNG, SVG, PDF, WebP, EPS, GIF, Binary output support
  • Reliability - Framework-agnostic, Laravel-ready design - Extensive test coverage ensuring ISO/IEC 18004 compliance

Getting Started

1. 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 amirezaeb/heroqr

2. Basic Usage

Example:

use HeroQR\Core\QRCodeGenerator;

$qrCode = (new QRCodeGenerator())
    ->setData('https://test.org') 
    ->generate();

$qrCode->saveTo('qrcode'); 

The saveTo() method automatically resolves and appends the appropriate file extension based on the selected output format.

3. Advanced Customization

Advanced configuration options for full control over QR code generation and validation.

Granular Customization: Fine-tune colors, size, logos, and typography. Smart Validation: Use the optional DataType to automatically validate inputs like URL, Email, Phone, Wi-Fi, and more.

Example:

use HeroQR\Core\QRCodeGenerator;
use HeroQR\DataTypes\DataType;

$qrCode = (new QRCodeGenerator())
    ->setData('aabrahimi1718@gmail.com', DataType::Email)
    ->setBackgroundColor(255, 255, 255, 0)
    ->setColor(0, 100, 200)
    ->setSize(1000)
    ->setLogo('../assets/HeroExpert.png', 100)
    ->setMargin(0)
    ->setEncoding('CP866')
    ->setErrorCorrectionLevel('Medium')
    ->setBlockSizeMode('None')
    ->setLabel(
        label: 'To Contact Me, Just Scan This QRCode',
        textAlign: 'left',
        textColor: ['r' => 0, 'g' => 100, 'b' => 200],
        fontSize: 35,
        margin: [15, 15, 15, 15]
    )
    ->generate('webp');

$qrCode->saveTo('custom-qrcode');

4. Customizing Shapes, Markers, and Cursors

HeroQR supports custom styling for QR modules, corner markers, and alignment cursors.

> This feature is available for PNG and SVG output formats.

Available Options:

  • Shapes (Modules): `S1` to `S4`
  • Markers (Corners): `M1` to `M6`
  • Cursors (Inner Markers): `C1` to `C6`

Example:

use HeroQR\Core\QRCodeGenerator;

$qrCode = (new QRCodeGenerator())
    ->setData('https://github.com/amirezaeb/heroqr')
    ->setSize(800)
    ->setBackgroundColor(0, 0, 0, 0) 
    ->setColor(0, 100, 200)
    ->generate('svg',[
            'Shape' => 'S2',
            'Marker' => 'M2',
            'Cursor' => 'C2'
        ]);

$qrCode->saveTo('custom-qr');

Examples

| Combination | Shape (Body) | Marker (Corner) | Cursor (Inner) | Preview | |:--------------:|------------------|--------------------|--------------------|:------------------------------------------------------------------------------------------------------:| | S1-M1-C1 | Square (Default) | Square (Default) | Square (Default) | View | | S2-M2-C2 | Circle (Custom) | Circle (Custom) | Circle (Custom) | View | | S3-M3-C3 | Star (Custom) | D-Drop-O (Custom) | D-Drop-O (Custom) | View | | S4-M4-C4 | Diamond (Custom) | D-Drop-I (Custom) | D-Drop-I (Custom) | View | | S4-M5-C5 | Diamond (Custom) | D-Drop-IO (Custom) | D-Drop-IO (Custom) | View | | S4-M6-C6 | Diamond (Custom) | Square-O (Custom) | Square-O (Custom) | View |

5. Advanced Output Options

HeroQR supports multiple output formats for flexible usage in web, CLI, and custom rendering environments.

Available Outputs

  • Raw string representation
  • Matrix object / 2D array
  • Base64 Data URI (for direct HTML embedding)
  • Multi-format export (PNG, SVG, GIF, WebP, EPS, PDF)

Example:

use HeroQR\Core\QRCodeGenerator;

$qrCode = (new QRCodeGenerator())
    ->setData('https://test.org') 
    ->generate();

# Raw binary string
$string = $qrCode->getString();

# Matrix object
$matrix = $qrCode->getMatrix();

# 2D array
$matrixArray = $qrCode->getMatrixAsArray();

# Base64 Data URI
$dataUri = $qrCode->getDataUri();

# Save to file
$qrCode->saveTo('qr_code_output');

Project Structure

HeroQR follows a modular architecture designed for scalability and maintainability.

src/
??? Contracts/
??? Core/
??? DataTypes/
??? Managers/
??? Customs/
??? Tests/

Module Overview:

  • Contracts: Core interfaces defining system boundaries and extensibility
  • Core: QR code generation engine
  • DataTypes: Input validation layer for structured data (URL, Email, WiFi, etc.)
  • Managers: Feature orchestration and lifecycle handling
  • Customs: Visual customization layer (Shapes, Markers, Cursors)
  • Tests: Unit and integration test suite

Support & Sponsorship

If HeroQR is useful in your projects, you can support its development by:

  • ? Starring the repository
  • ? Contributing via issues or pull requests
  • ? Donating via TON or USDT
  • ? Contacting us for sponsorship opportunities

GRAM (TON)

UQBejif4zPS57KWzz9VcqNHgRqLiOs72--xcoMyLkbnvyvn2

USDT (TRC-20)

TEbQ2K3kWF1TjE4yRuqp6hTH8FRr7n7xGX

Organizations interested in sponsoring HeroQR or featuring their brand in the documentation may contact us via the Contact section.

Contributing

Contributions are welcome.

  1. Fork the repository.
  2. Create a feature or bugfix branch.
  3. Implement your changes and add tests when necessary.
  4. Commit your changes using the Conventional Commits format.
  5. Push your branch and open a Pull Request.

Example:

git checkout -b feature/amazing-feature

git commit -m "feat: add support for custom frame colors"

git push origin feature/amazing-feature

Please provide a clear description of your changes and reference any related issues (e.g. Fixes #123).

License

HeroQR is open-sourced software licensed under the MIT License.

Contact

For inquiries, feedback, or collaborations, feel free to reach out via any of the following channels:


  Files folder image Files (77)  
File Role Description
Files folder image.github (1 directory)
Files folder imageassets (2 directories)
Files folder imagesrc (6 directories)
Files folder imagetests (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (77)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (77)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file CI.yml Data Auxiliary data

  Files folder image Files (77)  /  assets  
File Role Description
Files folder imageCursors (6 files)
Files folder imageMarkers (6 files)

  Files folder image Files (77)  /  assets  /  Cursors  
File Role Description
  Accessible without login Image file Cursor-1.png Icon Icon image
  Accessible without login Image file Cursor-2.png Icon Icon image
  Accessible without login Image file Cursor-3.png Icon Icon image
  Accessible without login Image file Cursor-4.png Icon Icon image
  Accessible without login Image file Cursor-5.png Icon Icon image
  Accessible without login Image file Cursor-6.png Icon Icon image

  Files folder image Files (77)  /  assets  /  Markers  
File Role Description
  Accessible without login Image file Marker-1.png Icon Icon image
  Accessible without login Image file Marker-2.png Icon Icon image
  Accessible without login Image file Marker-3.png Icon Icon image
  Accessible without login Image file Marker-4.png Icon Icon image
  Accessible without login Image file Marker-5.png Icon Icon image
  Accessible without login Image file Marker-6.png Icon Icon image

  Files folder image Files (77)  /  src  
File Role Description
Files folder imageContracts (1 file, 3 directories)
Files folder imageCore (1 file, 1 directory)
Files folder imageCustoms (4 files, 1 directory)
Files folder imageDataTypes (8 files)
Files folder imageManagers (6 files)
Files folder imageProviders (1 file)

  Files folder image Files (77)  /  src  /  Contracts  
File Role Description
Files folder imageCustoms (1 file, 2 directories)
Files folder imageDataTypes (1 file)
Files folder imageManagers (6 files)
  Accessible without login Plain text file QRCodeGeneratorInterface.php Class Class source

  Files folder image Files (77)  /  src  /  Contracts  /  Customs  
File Role Description
Files folder imageDrawers (3 files)
Files folder imageWriter (2 files)
  Accessible without login Plain text file AbstractCustomPaths.php Class Class source

  Files folder image Files (77)  /  src  /  Contracts  /  Customs  /  Drawers  
File Role Description
  Accessible without login Plain text file AbstractDrawer.php Class Class source
  Accessible without login Plain text file PngDrawer.php Class Class source
  Accessible without login Plain text file SvgDrawer.php Class Class source

  Files folder image Files (77)  /  src  /  Contracts  /  Customs  /  Writer  
File Role Description
  Accessible without login Plain text file AbstractPngWriter.php Class Class source
  Accessible without login Plain text file AbstractSvgWriter.php Class Class source

  Files folder image Files (77)  /  src  /  Contracts  /  DataTypes  
File Role Description
  Accessible without login Plain text file AbstractDataType.php Class Class source

  Files folder image Files (77)  /  src  /  Contracts  /  Managers  
File Role Description
  Accessible without login Plain text file AbstractWriterManager.php Class Class source
  Accessible without login Plain text file ColorManagerInterface.php Class Class source
  Accessible without login Plain text file EncodingManagerInterface.php Class Class source
  Accessible without login Plain text file LabelManagerInterface.php Class Class source
  Accessible without login Plain text file LogoManagerInterface.php Class Class source
  Accessible without login Plain text file OutputManagerInterface.php Class Class source

  Files folder image Files (77)  /  src  /  Core  
File Role Description
Files folder imageWriters (2 files)
  Accessible without login Plain text file QRCodeGenerator.php Class Class source

  Files folder image Files (77)  /  src  /  Core  /  Writers  
File Role Description
  Accessible without login Plain text file CustomPngWriter.php Class Class source
  Accessible without login Plain text file CustomSvgWriter.php Class Class source

  Files folder image Files (77)  /  src  /  Customs  
File Role Description
Files folder imageShapeDrawers (2 files)
  Accessible without login Plain text file CursorPaths.php Class Class source
  Accessible without login Plain text file ImageOverlay.php Class Class source
  Accessible without login Plain text file MarkerPaths.php Class Class source
  Accessible without login Plain text file ShapePaths.php Class Class source

  Files folder image Files (77)  /  src  /  Customs  /  ShapeDrawers  
File Role Description
  Accessible without login Plain text file PngShapeDrawer.php Class Class source
  Accessible without login Plain text file SvgShapeDrawer.php Class Class source

  Files folder image Files (77)  /  src  /  DataTypes  
File Role Description
  Accessible without login Plain text file DataType.php Class Class source
  Accessible without login Plain text file EmailValidator.php Class Class source
  Accessible without login Plain text file LocationValidator.php Class Class source
  Accessible without login Plain text file NoneValidator.php Class Class source
  Accessible without login Plain text file PhoneValidator.php Class Class source
  Accessible without login Plain text file TextValidator.php Class Class source
  Accessible without login Plain text file UrlValidator.php Class Class source
  Accessible without login Plain text file WifiValidator.php Class Class source

  Files folder image Files (77)  /  src  /  Managers  
File Role Description
  Accessible without login Plain text file ColorManager.php Class Class source
  Accessible without login Plain text file EncodingManager.php Class Class source
  Accessible without login Plain text file LabelManager.php Class Class source
  Accessible without login Plain text file LogoManager.php Class Class source
  Accessible without login Plain text file OutputManager.php Class Class source
  Accessible without login Plain text file WriterManager.php Class Class source

  Files folder image Files (77)  /  src  /  Providers  
File Role Description
  Accessible without login Plain text file HeroQRServiceProvider.php Class Class source

  Files folder image Files (77)  /  tests  
File Role Description
Files folder imageIntegration (3 files)
Files folder imageUnit (4 directories)

  Files folder image Files (77)  /  tests  /  Integration  
File Role Description
  Accessible without login Plain text file LogoQRCodeTest.php Class Class source
  Accessible without login Plain text file QRCodeExportTest.php Class Class source
  Accessible without login Plain text file StyledQRCodeTest.php Class Class source

  Files folder image Files (77)  /  tests  /  Unit  
File Role Description
Files folder imageCore (1 file, 1 directory)
Files folder imageCustoms (4 files)
Files folder imageDataTypes (7 files)
Files folder imageManagers (6 files)

  Files folder image Files (77)  /  tests  /  Unit  /  Core  
File Role Description
Files folder imageWriters (2 files)
  Accessible without login Plain text file QRCodeGeneratorTest.php Class Class source

  Files folder image Files (77)  /  tests  /  Unit  /  Core  /  Writers  
File Role Description
  Accessible without login Plain text file CustomPngWriterTest.php Class Class source
  Accessible without login Plain text file CustomSvgWriterTest.php Class Class source

  Files folder image Files (77)  /  tests  /  Unit  /  Customs  
File Role Description
  Accessible without login Plain text file CustomPathsTest.php Class Class source
  Accessible without login Plain text file ImageOverlayTest.php Class Class source
  Accessible without login Plain text file PngShapeDrawerTest.php Class Class source
  Accessible without login Plain text file SvgShapeDrawerTest.php Class Class source

  Files folder image Files (77)  /  tests  /  Unit  /  DataTypes  
File Role Description
  Accessible without login Plain text file DataTypeTest.php Class Class source
  Accessible without login Plain text file EmailValidatorTest.php Class Class source
  Accessible without login Plain text file LocationValidatorTest.php Class Class source
  Accessible without login Plain text file PhoneValidatorTest.php Class Class source
  Accessible without login Plain text file TextValidatorTest.php Class Class source
  Accessible without login Plain text file UrlValidatorTest.php Class Class source
  Accessible without login Plain text file WifiValidatorTest.php Class Class source

  Files folder image Files (77)  /  tests  /  Unit  /  Managers  
File Role Description
  Accessible without login Plain text file ColorManagerTest.php Class Class source
  Accessible without login Plain text file EncodingManagerTest.php Class Class source
  Accessible without login Plain text file LabelManagerTest.php Class Class source
  Accessible without login Plain text file LogoManagerTest.php Class Class source
  Accessible without login Plain text file OutputManagerTest.php Class Class source
  Accessible without login Plain text file WriterManagerTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0