An easy-to-use PHP QR Code generator with first-party support for Laravel. from ByteFum
A PHP QR Code Generator with first-party support for Laravel
Jan 12, 2022
Auther Avatar HR

Simple QrCode is an easy-to-use wrapper for the popular Laravel framework based on the great work provided by Bacon/BaconQRCode.This package has a lot of advanced customization options and different features. You can see different examples here.


1. Installation

 First, You've to install the imagick PHP extension if you plan on using the png image format.

Next, You've to run this command for the installation via composer.

composer require simplesoftwareio/simple-qrcode "~4"

Laravel will automatically pick up and install the package.


2. Usage

Basic Usage

// All examples below assume you are pulling in the QrCode facade with the following line of code. The Facade is auto-loaded for Laravel users. use SimpleSoftwareIO\QrCode\Facades\QrCode;

Using the QrCode Generator is very easy. The most basic syntax is:

use SimpleSoftwareIO\QrCode\Facades\QrCode;

QrCode::generate('Make me into a QrCode!');

This will make a QrCode that says "Make me into a QrCode!"


3. Generate (string $data, string $filename = null)

Generate is used to make the QrCode.

QrCode::generate('Make me into a QrCode!');

Generate by default will return an SVG image string. You can print this directly into a modern browser within Laravel's Blade system with the following:

{!! QrCode::generate('Make me into a QrCode!'); !!}

The generate method has a second parameter that will accept a filename and path to save the QrCode.

QrCode::generate('Make me into a QrCode!', '../public/qrcodes/qrcode.svg');


4. Format (string $format

Three formats are currently supported; png, eps, and svg. To change the format use the following code:

  • QrCode::format('png'); //Will return a png image
  • QrCode::format('eps'); //Will return a eps image
  • QrCode::format('svg'); //Will return a svg image

imagick is required in order to generate a png image.


5. Size (int $size)

You can change the size of a QrCode by using the size method. Simply specify the size desired in pixels using the following syntax:



6. Color (int $red, int $green, int $blue, int $alpha = null)

Be careful when changing the color of a QrCode, as some readers have a very difficult time reading QR codes in color.

All colors must be expressed in RGBA (Red Green Blue Alpha). You can change the color of a QR code by using the following:

QrCode::color(255, 0, 0); // Red QrCode
QrCode::color(255, 0, 0, 25); //Red QrCode with 25% transparency 


7. Style (string $style, float $size = 0.5)

The style can be easily swapped out with square, dot, or round. This will change the blocks within the QrCode. The second parameter will affect the size of the dots or roundness.

QrCode::style('dot'); // Uses the `dot` style.


8. Margin (int $margin)

The ability to change the margin around a QrCode is also supported. Simply specify the desired margin using the following syntax:



9. Error Correction (string $errorCorrection)

Changing the level of error correction is easy. Just use the following syntax:



10. Encoding (string $encoding)

Change the character encoding that is used to build a QrCode.

By default, ISO-8859-1 is selected as the encoder. Read more about character encoding.

You can change this to any of the following:

QrCode::encoding('UTF-8')->generate('Make me a QrCode with special symbols ♠♥!!');


Usage Outside of Laravel

You may use this package outside of Laravel by instantiating a new Generator class.

use SimpleSoftwareIO\QrCode\Generator;

$qrcode = new Generator;
$qrcode->size(500)->generate('Make a qrcode without Laravel!');

There are a lot more awesome features & options in this package.



Recommended Blog
Nishan Avatar
Quick Enquire