tuncaybahadir/quar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tuncaybahadir/quar

Composer 安装命令:

composer require tuncaybahadir/quar

包简介

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

README 文档

README

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.

tuncaybahadir/quar 适用场景与选型建议

tuncaybahadir/quar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105.14k 次下载、GitHub Stars 达 76, 最近一次更新时间为 2025 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator」 「php」 「qrcode」 「laravel」 「qr」 「php 8.2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tuncaybahadir/quar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tuncaybahadir/quar 我们能提供哪些服务?
定制开发 / 二次开发

基于 tuncaybahadir/quar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 105.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 78
  • 点击次数: 24
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 76
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

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