Skip to content

tuncaybahadir/quar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qr Code Generator For Laravel

Latest Stable Version  php  Laravel  Downloads  License

Introduction

To generate Qr Code with Laravel, Quar references packages provided by Bacon/BaconQrCode and simplesoftwareio/simple-qrcode. The Quar package is a new qr code generation package with compatibility for Laravel 10, Laravel 11, Laravel 12, Laravel 13 and Php 8.2, Php 8.3, Php 8.4, Php 8.5.


Example 17


Minimum Requirements

  • PHP 8.2+
  • Laravel 10+

Installing

Use Composer to install it:

composer require tuncaybahadir/quar

Simple usage

use tbQuar\Facades\Quar;
    
$qr = Quar::generate('Quar package create qr code');

And use it in your blade template this way:

<div>
    {{ $qr }}
</div>

Simple usage Response

Example 1


Example of Setting Qr Code Size

use tbQuar\Facades\Quar;
    
$qr = Quar::size(61)
            ->generate('Quar package create qr code');

Qr Code Size Response

Example 2


Example of Setting Qr Code Version

QR codes have 40 versions (1-40); a higher version provides a larger grid and therefore more data capacity. By default the version is selected automatically based on the content and the error correction level. You may force a specific version with the version() method.

Any integer between 1 and 40 is accepted. For readability, VERSION_1 through VERSION_40 constants are also available on the Quar facade, so version(13) and version(Quar::VERSION_13) are equivalent.

use tbQuar\Facades\Quar;
    
$qr = Quar::version(13)
            ->generate('Quar package create qr code');

// Equivalent, using the constant
$qr = Quar::version(Quar::VERSION_13)
            ->generate('Quar package create qr code');

$qr = Quar::size(300)
            ->eye('ring')
            ->style('round', 0.9)
            ->version(Quar::VERSION_13)
            ->margin(2)
            ->gradient(20, 192, 241 , 164, 29, 52 , 'vertical')
            ->generate('Quar package create qr code');

$qr = Quar::size(300)
            ->eye('square')
            ->eyeColorFromHex('0', '#710616', '#710616')
            ->eyeColorFromHex('1', '#7ab9e7', '#7ab9e7')
            ->eyeColorFromHex('2', '#fcb811', '#fcb811')
            ->style('round', 0.9)
            ->version(Quar::VERSION_25)
            ->margin(2)
            ->gradient(20, 192, 241 , 164, 29, 52 , 'vertical')
            ->generate('Quar package create qr code');

$qr = Quar::size(500)
            ->margin(2)
            ->version(Quar::VERSION_40)
            ->generate('Version 40 (177×177). Content: "Version 40 QR Code can contain up to 1852 chars ..." (and followed by four paragraphs of ASCII text describing QR codes). The text refers to a QR Code with a "Level H" error correction. Other levels provide higher capacity.');

Attention : The version must be between 1 and 40. If the content does not fit into the requested version, a WriterException is thrown. When version() is not used, the smallest fitting version is selected automatically, exactly as before.

QR Code Versions Response

Example 30

Example 31

Example 32

Example 33


Example of Setting Qr Code Detection Markers

Available Markers Type

  • square: Default Marker Type
  • rounded
  • circle
  • ring
use tbQuar\Facades\Quar;
    
$qr = Quar::eye('rounded')
            ->generate('Quar package create qr code');

Qr Code Markers Response

Example 12     Example 3      Example 13     Example 21     


Example of Setting Qr Code Body Pattern Style

Available Body Pattern

  • square: Default Pattern
  • dot
  • round
  • star
  • vertigo

Attention : The maximum smoothness value for square, dot and round designs is 0.9 and the maximum smoothness value for star and vertigo designs is 0.5.

use tbQuar\Facades\Quar;
    
$qr = Quar::style('dot', 0.9)
            ->generate('Quar package create qr code');

Qr Code Body Pattern Style Response

Example 14     Example 15      Example 16     Example 22      Example 23


Example of Setting Qr Code Gradient Coloring

Available Gradient Type

  • vertical
  • horizontal
  • diagonal
  • inverse_diagonal
  • radial
use tbQuar\Facades\Quar;
    
$qr = Quar::eye('rounded')
            ->size(161)
            ->gradient(20, 192, 241 , 164, 29, 52 , 'vertical')
            ->generate('Quar package create qr code');

Qr Code Gradient Coloring Response

Example 9


Qr Code Coloring Markers Example 1

use tbQuar\Facades\Quar;
    
$qr = Quar::eye('square')
            ->eyeColor(0, 113, 6, 22, 113, 6, 22)
            ->eyeColor(1, 122, 185, 231, 122, 185, 231)
            ->eyeColor(2, 252, 184, 17)
            ->size(161)
            ->generate('Quar package create qr code');

Qr Code Coloring Markers Response 1

Example 4


Qr Code Hex Code With Coloring Markers Example 2

use tbQuar\Facades\Quar;
    
$qr = Quar::eye('square')
            ->eyeColorFromHex('0', '#710616', '#710616')
            ->eyeColorFromHex('1', '#7ab9e7', '#7ab9e7')
            ->eyeColorFromHex('2', '#fcb811', '#fcb811')
            ->size(161)
            ->generate('Quar package create qr code');

Qr Code Hex Code With Coloring Markers Response 2

Example 17


Qr Code Coloring Example 1

use tbQuar\Facades\Quar;
    
$qr = Quar::color(50, 168, 82)
            ->size(161)
            ->eye('circle')
            ->generate('Quar package create qr code');

Qr Code Coloring Response 1

Example 5


Qr Code Hex Code With Coloring Example 2

use tbQuar\Facades\Quar;
    
$qr = Quar::color('#32a852')
            ->size(161)
            ->eye('circle')
            ->generate('Quar package create qr code');

Qr Code Hex Code With Coloring Response 2

Example 18


Example Of Coloring Qr Code Background With Hex Code 1

use tbQuar\Facades\Quar;
    
$qr = Quar::color('#710616')
            ->backgroundColor('#7ab9e7')
            ->size(261)
            ->eye('circle')
            ->generate('Quar package create qr code');

Example Of Coloring Qr Code Background With Hex Code 1

Example 19


Example Of Coloring The Background Of Qr Code 2

use tbQuar\Facades\Quar;
    
$qr = Quar::color(113, 6, 22)
            ->backgroundColor(122, 185, 231)
            ->size(261)
            ->eye('circle')
            ->generate('Quar package create qr code');

Sample Result Of Coloring The Background Of Qr Code Response 2

Example 20


Qr Code And Markers Coloring Example

use tbQuar\Facades\Quar;
    
$qr = Quar::color(235, 12, 83)
            ->size(161)
            ->eye('rounded')
            ->eyeColor(0, 113, 6, 22, 113, 6, 22)
            ->eyeColor(1, 122, 185, 231, 122, 185, 231)
            ->eyeColor(2, 252, 184, 17)
            ->generate('Quar package create qr code');

Qr Code and Marker Coloring Response

Example 6


Example of Saving Qr Code as a Png File

use tbQuar\Facades\Quar;
    
        $qrCodeFileName = md5(random_int(0, 9999999).date('H:i:s d.m.Y')).'_qr_code';
        $qrCodeData = 'Quar package create qr code';
        $qrCodeDirectory = storage_path('app/public/qr-code-images/');

        Quar::format('png')
            ->color(155, 155, 200)
            ->size(200)
            ->eye('rounded')
            ->generate($qrCodeData, $qrCodeDirectory.$qrCodeFileName.'.png');

        $qrCode = url('storage/qr-code-images/'.$qrCodeFileName.'.png');

And use it in your blade template this way:

<div>
    <img src="{{ $qrCode }}" />
</div>

Saving Qr Code as a File Response

Example 7     Example 8


Example of Compressing and Saving a Qr Code as a Png File

use tbQuar\Facades\Quar;
    
        $qrCodeFileName = md5(random_int(0, 9999999).date('H:i:s d.m.Y')).'_qr_code';
        $qrCodeData = 'Quar package create qr code';
        $qrCodeDirectory = storage_path('app/public/qr-code-images/');

        Quar::format('png')
            ->setPngCompression(50)
            ->color(155, 155, 200)
            ->size(200)
            ->eye('rounded')
            ->generate($qrCodeData, $qrCodeDirectory.$qrCodeFileName.'.png');

        $qrCode = url('storage/qr-code-images/'.$qrCodeFileName.'.png');

Example of Adding Logo on QR Code

Attention !!! : Due to a bug in the BaconQrCode package, you must set the margin value to 1 or higher during logo insertion. Otherwise the qr code is generated incorrectly.

Example 1:

use tbQuar\Facades\Quar;
    
        $qr = Quar::format('png')
            ->margin(1)
            ->merge(public_path('php.png'), .2, true)
            ->size(400)
            ->generate('Quar package create qr code');
            
            return view('test', [
                'qrCode' => base64_encode($qr),
            ]);

Example 2:

use tbQuar\Facades\Quar;
    
        $qr = Quar::format('png')
            ->margin(1)
            ->eye('rounded')
            ->merge(public_path('php.png'), .3, true)
            ->size(200)
            ->gradient(100, 20, 5 , 7, 9, 12 , 'VERTICAL')
            ->generate('Quar package create qr code');
            
            return view('test', [
                'qrCode' => base64_encode($qr),
            ]);

And use it in your blade template this way:

<div>
    <img src="data:image/png;base64,{{ $qrCode }}" />
</div>

Adding Logo on Qr Code Sample Code Result 1:

Example 10

Adding Logo on Qr Code Sample Code Result 2:

Example 11

Example of Adding Logo on QR Code with Laravel Conditionable Trait class

Example :

use tbQuar\Facades\Quar;

        $qr = Quar::format('png')
            ->margin(1)
            ->when(($logo = config('app.company.logo')) && file_exists($logo))
            ->merge($logo, .25, absolute: true)
            ->size(400)
            ->generate('Quar package create qr code', $path);

            return view('test', [
                'qrCode' => base64_encode($qr),
            ]);

Adding Text Around a QR Code

Example :

use tbQuar\Facades\Quar;

        $qr = Quar::size(300)
            ->withText('Quar Code Package')
            ->generate('Quar package create qr code');

Example Result :

Example 27

Customizing the Text

Example :

use tbQuar\Facades\Quar;

        $qr = Quar::size(300)
            ->withText('Quar Code Package')
            ->configureText(function($text) {
                $text->setTextColor('#54ac6e')
                    ->setFontSize(12)
                    ->setPosition('top-right')
                    ->setPadding(25)
                    ->setBackgroundColor('#151521')
                    //->setFont('/path/to/font.ttf')
                    ->setBackgroundOpacity(0.1);
            })
            ->generate('Quar package create qr code');

Example Result :

Example 28

Available Text Positions

  • top,
  • bottom : Default Position,
  • left,
  • right,
  • top-left,
  • top-right,
  • bottom-left,
  • bottom-right,

Example :

use tbQuar\Facades\Quar;

        $qr = Quar::size(300)
            ->withText('🇹🇷 Türkiye 🇹🇷')
            ->configureText(function($text) {
                $text->setTextColor('#ce2026')
                    ->setFontSize(30)
                    ->setPosition('top')
                    ->setBackgroundOpacity(0.1);
            })
            ->generate('Quar package create qr code');

Example Result :

Example 29

Authors


Contributing

Pull requests and issues are more than welcome.

About

A simple qr code generation tool for your projects with Laravel 10, 11, 12, 13 versions, Php 8.2, 8.3, 8.4 and 8.5

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages