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
2025-09-15 (18 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
heroqr 1.1.9Custom (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: 23
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 - A Powerful PHP QR Code Library

Last Updated: Apr 2025 Author: Amirreza Ebrahimi Contributors: None yet License: MIT License

  • HeroQR is an advanced and modular PHP library designed to simplify the creation, customization, and management of QR codes. Whether you need a basic QR code or a highly customized one with embedded logos, colors, markers, and cursors, HeroQR has you covered. You can fully customize the appearance of your QR code by adjusting the markers (for corner customization), cursors (for design enhancements), and even the shapes of the QR code itself. This level of customization allows you to tailor your QR codes to fit your needs precisely.

Table of Contents

Features

  • Advanced Customization Options: - Adjust logo size and embed logos into QR codes. - Automatically adjust QR code layout and margins to ensure proper scaling. - Change QR code and background colors (RGB or RGBA), including transparency options. - Add customizable labels with options for color (RGB or RGBA), size, alignment, and margin. - Support for various encoding formats such as BASE64, UTF-8, UTF-16, and others.
  • Shape, Marker, and Cursor Customization: HeroQR offers enhanced design control by allowing customization of the geometric shape of QR code points, as well as markers and cursors.These features are support: - `S` for Shape type. - `M` for Marker type. - `C` for Cursor type. - Available marker and cursor types: - Shapes: `S1` - `S2` - `S3` - `S4` - Markers: `M1` - `M2` - `M3` - `M4` - `M5` - `M6` - Cursors: `C1` - `C2` - `C3` - `C4` - `C5` - `C6` - Note: This feature is available only for PNG format at the moment, but additional formats will be supported in future updates.
  • Multi-Format Data Encoding: Support for encoding a wide range of data types ? including URLs, plain text, emails, business cards, and payment information ? so you can generate the right QR code for any use case.
  • Built-In Data Validation: To prevent errors and ensure reliability, the library automatically validates input for common types such as URLs, emails, phone numbers, IP addresses, and Wi-Fi credentials before encoding.
  • Flexible Export Options: QR codes can be exported in various formats, including PDF, SVG, PNG, Binary, GIF, EPS, and WebP. If custom shapes, markers, or cursors are not required, you can choose from these formats for the output.
  • Framework Ready: Seamlessly integrates with modern frameworks like Laravel, making it a perfect fit for contemporary web applications.

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

  • Generate a simple QR code in just a few lines of code:

Example :

require 'vendor/autoload.php';
use HeroQR\Core\QRCodeGenerator;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    # Set the data to be encoded in the QR code
    ->setData('https://test.org') 
    # Generate the QR code in PNG format (default)
    ->generate();

# Save the generated QR code to a file named 'qrcode.png'
$qrCode->saveTo('qrcode'); 

3. Advanced Customization

  • Fully customize the appearance and functionality of your QR code with automatic data validation:

    - Customization Options: Modify various parameters such as size, color, logo, and more. - Automatic Data Validation: By using `DataType` (optional), the library automatically validates the type of data being encoded (e.g., URL, Email, Phone, Location, Wifi, Text).

Example :

require 'vendor/autoload.php';

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

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    # Set data to be encoded and validate it as an Email
    ->setData('[email protected]', DataType::Email)  
    # Set background and QR code colors
    ->setBackgroundColor('#ffffffFF')
    # Set the QR code's color
    ->setColor('#fc031c')
    # Set the size of the QR code (default size is 800)
    ->setSize(900)
    # Set the logo to be embedded at the center (default size is 80)
    ->setLogo('../assets/HeroExpert.png', 100 )
    # Set the margin around the QR code (default size is 10)
    ->setMargin(0)
    # Set character encoding for the QR code (default encoding is UTF-8)
    ->setEncoding('CP866')
    # Set the error correction level for the QR code (default is "High")
    ->setErrorCorrectionLevel('Medium')
    # Set the block size mode to "None" (default is "Margin")
    ->setBlockSizeMode('None')
    # Customize the label with text, alignment, color, and font size
    ->setLabel(
        # Label Text
        label: 'To Contact Me, Just Scan This QRCode',
        # Label align (default: center)
        textAlign: 'right',
        # Label text color (default: #000000)
        textColor: '#fc031c',
        # Label size (default: 50)
        fontSize: 35,
        # Label margin (default: 0, 10, 10, 10)
        margin: [15, 15, 15, 15] 
    )
    # Generate the QR code in WebP format
    ->generate('webp');

# Save the generated QR code to a file
$qrCode->saveTo('custom-qrcode');

With these options, you can create visually appealing QR codes that align with your design needs.

4. Customizing Shapes, Markers, and Cursors (PNG Only)

HeroQR allows you to fully customize the markers, cursors, and shapes of your QR codes. This feature is exclusive to PNG output. To use this feature, specify the output format with generate('png', [ ... ]) and include the desired parameters for shape, marker, and cursor types.

Available Options:

  • Shapes: `S1` - `S2` - `S3` - `S4`
  • Markers: `M1` - `M2` - `M3` - `M4` - `M5` - `M6`
  • Cursors: `C1` - `C2` - `C3` - `C4` - `C5` - `C6`

These options allow you to modify the appearance of the QR code, making it more personalized or stylish. Shapes modify the corners, markers change the patterns on the dots, and cursors adjust the positioning pointers.

Example :

require 'vendor/autoload.php';

use HeroQR\Core\QRCodeGenerator;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    ->setData('https://example.com')
    ->setSize(800)
    ->setBackgroundColor('#ffffffFF')
    ->setColor('#000000')
    # Customize the Shape (Circle), Marker (Circle), and Cursor (Circle)
    ->generate('png',[
            'Shape' => 'S2',
            'Marker' => 'M2',
            'Cursor' => 'C2'
        ]);

# Save the generated QR code with customizations
$qrCode->saveTo('custom-qr');

Example QR Code Outputs with Different Combinations : Below are some examples of QR codes generated using various combinations of shapes, markers, and cursors:

| Combination | Shape | Marker | Cursor | 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 |

  • Experiment with Different Combinations: In this section, you can experiment with various combinations of shapes, markers, and cursors to create unique QR codes that best suit your needs. Each combination will impact the appearance of the QR code, from the corners and points to the positioning of the markers. Simply adjust the parameters to customize your QR codes.

5. Advanced Output Options

HeroQR provides advanced output capabilities, offering flexibility and compatibility for various use cases, from web embedding to raw data manipulation:

  • String Representation : Retrieve the QR code as a raw string, which can be useful for direct processing or custom transformations.
  • Matrix Output : Represent the QR code as a matrix (2D array) of bits, where each block of the matrix corresponds to a specific piece of the encoded data. You can retrieve the matrix in two forms: - As a `Matrix` object. - As a 2D array, which makes it easier to manipulate or display directly in some applications.
  • Base64 Encoding : Generate the QR code as a Base64-encoded string, which is ideal for embedding directly in HTML, emails, or other media.
  • Saving to Different Formats : You can save the QR code in a variety of formats such as PNG, SVG, GIF, WebP, EPS, PDF, Binary, and more. The format is automatically determined based on the desired output type.

Example

require 'vendor/autoload.php';

use HeroQR\Core\QRCodeGenerator;

# Create a QRCodeGenerator instance
$qrCodeManager = new QRCodeGenerator();

$qrCode = $qrCodeManager
    # Set the data to be encoded in the QR code
    ->setData('https://test.org') 
    # Generate the QR code in PNG format (default)
    ->generate();

# Get the QR code as a string representation
$string = $qrCode->getString();

# Get the QR code as a matrix object
$matrix = $qrCode->getMatrix();

# Get the matrix as a 2D array
$matrixArray = $qrCode->getMatrixAsArray();

# Get the QR code as Base64 encoding for embedding in HTML
$dataUri = $qrCode->getDataUri();

# Save the QR code to a file in the desired format (WebP, GIF, Binary, Esp, PNG, SVG, PDF)
$qrCode->saveTo('qr_code_output');

Project Structure

The modular structure of HeroQR is designed to enhance efficiency and scalability, making it easier to use, maintain, and expand:

  • Contracts : Defines interfaces for the core components, ensuring consistency and reusability across the system.
  • Core : Houses the primary logic for generating and managing QR codes, acting as the foundation of the library.
  • DataTypes : Provides definitions and automatic validation for various data types (WiFi, Location, URL, Email, Phone, Text). This eliminates the need for users to manually validate their input.
  • Managers : Oversees the customization and processing of QR codes, enabling users to have full control over the appearance and functionality of their QR codes.
  • Customs : The Customs module allows advanced QR code customization, including shapes, cursors, markers, line colors, and other visual elements, perfect for creating unique and tailored designs.
  • Tests : Contains unit and integration tests for the library's core functionality. These tests ensure the library works as expected, providing confidence in the stability and correctness of the code.

Contributing

We welcome contributions and appreciate your interest in improving the project! Here's how you can contribute:

  1. Fork the repository: Create your own copy of the repository by forking it.
  2. Clone your fork: Clone the repository to your local machine:
    git clone https://github.com/AmirezaEb/HeroQR.git
    
  3. Create a feature branch: Create a new branch for your feature or bug fix.
  4. Make changes: Work on your feature or fix the issue.
  5. Write tests: Ensure your changes are covered by tests. If you're fixing a bug, add a test to verify the fix.
  6. Commit your changes: Commit your changes with clear, descriptive messages following a conventional format.
git commit -m '<type>[optional scope]: <description>'

  1. Push your branch: Push your changes to your forked repository branch.
git push origin feature-name

  1. Open a Pull Request: Once your branch is pushed, open a Pull Request on GitHub for review. Be sure to: - Provide a clear description of what your changes do. - Include any relevant issue numbers (e.g., Fixes #123).
  2. Participate in the review process: After submitting the pull request, review any feedback and make necessary changes.

We?ll review and merge your changes as soon as possible. Thank you for contributing!

License

HeroQR is released under the MIT License, giving you the freedom to use, modify, and distribute it.

Contact

For inquiries or feedback, feel free to reach out via email, GitHub issues, or LinkedIn:

Transform your projects with HeroQR today! ?


  Files folder image Files (67)  
File Role Description
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 (67)  /  assets  
File Role Description
Files folder imageCursors (6 files)
Files folder imageMarkers (6 files)

  Files folder image Files (67)  /  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 (67)  /  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 (67)  /  src  
File Role Description
Files folder imageContracts (1 file, 3 directories)
Files folder imageCore (1 file, 1 directory)
Files folder imageCustoms (5 files)
Files folder imageDataTypes (7 files)
Files folder imageManagers (6 files)
Files folder imageProviders (1 file)

  Files folder image Files (67)  /  src  /  Contracts  
File Role Description
Files folder imageCustoms (3 files)
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 (67)  /  src  /  Contracts  /  Customs  
File Role Description
  Accessible without login Plain text file AbstractCustomPaths.php Class Class source
  Accessible without login Plain text file AbstractWriter.php Class Class source
  Accessible without login Plain text file Drawer.php Class Class source

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

  Files folder image Files (67)  /  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 (67)  /  src  /  Core  
File Role Description
Files folder imageWriters (1 file)
  Accessible without login Plain text file QRCodeGenerator.php Class Class source

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

  Files folder image Files (67)  /  src  /  Customs  
File Role Description
  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 ShapeDrawers.php Class Class source
  Accessible without login Plain text file ShapePaths.php Class Class source

  Files folder image Files (67)  /  src  /  DataTypes  
File Role Description
  Accessible without login Plain text file DataType.php Class Class source
  Accessible without login Plain text file Email.php Class Class source
  Accessible without login Plain text file Location.php Class Class source
  Accessible without login Plain text file Phone.php Class Class source
  Accessible without login Plain text file Text.php Class Class source
  Accessible without login Plain text file Url.php Class Class source
  Accessible without login Plain text file Wifi.php Class Class source

  Files folder image Files (67)  /  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 (67)  /  src  /  Providers  
File Role Description
  Accessible without login Plain text file HeroQRServiceProvider.php Class Class source

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

  Files folder image Files (67)  /  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 (67)  /  tests  /  Unit  
File Role Description
Files folder imageCore (1 file, 1 directory)
Files folder imageCustoms (2 files)
Files folder imageDataTypes (7 files)
Files folder imageManagers (6 files)

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

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

  Files folder image Files (67)  /  tests  /  Unit  /  Customs  
File Role Description
  Accessible without login Plain text file ImageOverlayTest.php Class Class source
  Accessible without login Plain text file ShapeDrawersTest.php Class Class source

  Files folder image Files (67)  /  tests  /  Unit  /  DataTypes  
File Role Description
  Accessible without login Plain text file DataTypeTest.php Class Class source
  Accessible without login Plain text file EmailTest.php Class Class source
  Accessible without login Plain text file LocationTest.php Class Class source
  Accessible without login Plain text file PhoneTest.php Class Class source
  Accessible without login Plain text file TextTest.php Class Class source
  Accessible without login Plain text file UrlTest.php Class Class source
  Accessible without login Plain text file WifiTest.php Class Class source

  Files folder image Files (67)  /  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