thinkphp6: 生成带logo的二维码(php 8.1.1 / thinkphp v6.0.10LTS )
2022/1/15 11:33:49
本文主要是介绍thinkphp6: 生成带logo的二维码(php 8.1.1 / thinkphp v6.0.10LTS ),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一,qr-code代码库的地址:
https://github.com/endroid/qr-code
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,用composer下载:
1,下载liuhongdi@lhdpc:/data/php/admapi$ composer require endroid/qr-code2,查看已下载的qr-code库的版本:
liuhongdi@lhdpc:/data/php/admapi$ composer show endroid/qr-code name : endroid/qr-code descrip. : Endroid QR Code keywords : code, endroid, php, qr, qrcode versions : * 4.4.7 type : library license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText homepage : https://github.com/endroid/qr-code source : [git] https://github.com/endroid/qr-code.git d9f12af739c11c70fa1e8132dba8f849395e939b dist : [zip] https://api.github.com/repos/endroid/qr-code/zipball/d9f12af739c11c70fa1e8132dba8f849395e939b d9f12af739c11c70fa1e8132dba8f849395e939b path : /data/php/admapi/vendor/endroid/qr-code names : endroid/qr-code support issues : https://github.com/endroid/qr-code/issues source : https://github.com/endroid/qr-code/tree/4.4.7 autoload psr-4 Endroid\QrCode\ => src/ requires bacon/bacon-qr-code ^2.0 php ^7.4||^8.0 requires (dev) endroid/quality dev-master ext-gd * khanamiryan/qrcode-detector-decoder ^1.0.4 setasign/fpdf ^1.8.2 suggests ext-gd Enables you to write PNG images khanamiryan/qrcode-detector-decoder Enables you to use the image validator roave/security-advisories Makes sure package versions with known security issues are not installed setasign/fpdf Enables you to use the PDF writer可以看到版本是4.4.7
三,php代码:
controller/Article.php<?php declare (strict_types = 1); namespace app\controller; use Endroid\QrCode\Color\Color; use Endroid\QrCode\Encoding\Encoding; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow; use Endroid\QrCode\QrCode; use Endroid\QrCode\Label\Label; use Endroid\QrCode\Logo\Logo; use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; use Endroid\QrCode\Writer\PngWriter; class Article extends BaseController { //生成pr code public function qr() { $writer = new PngWriter(); // Create QR code $qrCode = QrCode::create('https://www.iliangcang.com') ->setEncoding(new Encoding('UTF-8')) ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow()) ->setSize(300) ->setMargin(10) ->setRoundBlockSizeMode(new RoundBlockSizeModeMargin()) ->setForegroundColor(new Color(0, 0, 0)) ->setBackgroundColor(new Color(255, 255, 255)); // Create generic logo //logo是放在app/asset/目录下 $logo = Logo::create(app()->getRootPath()."/app/asset/logo.png") ->setResizeToWidth(50); // Create generic label $label = Label::create('良仓.生活美学') ->setTextColor(new Color(0, 0, 0)); $result = $writer->write($qrCode, $logo, $label); header('Content-Type: '.$result->getMimeType()); echo $result->getString(); exit; } }
四,测试效果
访问:http://127.0.0.1:8000/article/qr返回:
五,查看php和thinkphp的版本:
php:liuhongdi@lhdpc:/data/php/admapi$ php --version PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies with Zend OPcache v8.1.1, Copyright (c), by Zend Technologiesthinkphp:
liuhongdi@lhdpc:/var/www/html$ cd /data/php/admapi/ liuhongdi@lhdpc:/data/php/admapi$ php think version v6.0.10LTS
这篇关于thinkphp6: 生成带logo的二维码(php 8.1.1 / thinkphp v6.0.10LTS )的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享
- 2024-11-01开源 PHP 商城项目 CRMEB 安装和使用教程
- 2024-11-01用php和mysql写无限分类,有哪几种方法-icode9专业技术文章分享
- 2024-10-31php数据分表导出时部分数据无法导出什么原因-icode9专业技术文章分享
- 2024-10-30有经验的 PHP 开发者学习一门新的编程语言,有哪些推荐的有前景的语言-icode9专业技术文章分享
- 2024-10-21php 检测图片是否篡改过-icode9专业技术文章分享
- 2024-10-20fruitcake/php-cors 该怎么使用-icode9专业技术文章分享
- 2024-10-18PHP7.1可以使用哪个版本的swoole-icode9专业技术文章分享