定制 tuncaybahadir/quar 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tuncaybahadir/quar

最新稳定版本:1.7.0

Composer 安装命令:

composer require tuncaybahadir/quar

包简介

A simple QR Code generation tool for your projects with Laravel 10, 11, 12 versions, php 8.2, 8.3, 8.4 and 8.5

README 文档

README

Latest Stable Version  php  Laravel  Downloads  License

Introduction

To generate Qr Code with Laravel, Quar references packages provided by [Bacon/BaconQrCode] (https://github.com/Bacon/BaconQrCode) and [simplesoftwareio/simple-qrcode] (https://github.com/SimpleSoftwareIO/simple-qrcode). The Quar package is a new qr code generation package with compatibility for Laravel 10, Laravel 11, Laravel 12 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 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.

统计信息

  • 总下载量: 37.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 63
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 63
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-17