二维码Qrcode Library
二维码Qrcode Library
插件官网:https://qrcode-library.readthedocs.io/en/latest/#yii2
composer 安装
php composer.phar require 2amigos/qrcode-library:~1.1
or add
"2amigos/qrcode-library": "^2.0"
执行 composer update
用法
- 在控制器中使用
use Da\QrCode\QrCode;$qrCode = (new QrCode('This is my text'))->setSize(250)->setMargin(5)->useForegroundColor(51, 153, 255);// now we can display the qrcode in many ways
// saving the result to a file:$qrCode->writeFile(__DIR__ . '/code.png'); // writer defaults to PNG when none is specified// display directly to the browser
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
exit(); //不能掉,否则系统报头信息已发送异常
?> //第二种显示
<?php
// or even as data:uri url
echo '<img src="' . $qrCode->writeDataUri() . '">';
exit(); //不能掉,否则系统报头信息已发送异常
?>
或者代码都写在一起
use Da\QrCode\QrCode;$qrCode = (new QrCode('This is my text'))->setSize(250)->setMargin(5)->useForegroundColor(51, 153, 255);$imgDisplay = false;
if ($imgDisplay ) {echo '<img src="' . $qrCode->writeDataUri() . '">';
} else {// now we can display the qrcode in many ways// saving the result to a file:$qrCode->writeFile(__DIR__ . '/code.png'); // writer defaults to PNG when none is specified// display directly to the browser header('Content-Type: '.$qrCode->getContentType());echo $qrCode->writeString();
}exit();
?>
- 设置为插件 QrCodeComponent
配置
// in components config of Yii2 app'components' => [
// ... 'qr' => ['class' => '\Da\QrCode\Component\QrCodeComponent','label' => '2amigos consulting group llc','size' => 500 // big and nice :D// ... you can configure more properties of the component here]
// ...
]
使用
$qr = Yii::$app->get('qr');Yii::$app->response->format = Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', $qr->getContentType());return $qr->setText('https://2amigos.us')->setLabel('2amigos consulting group llc')->writeString();
- 做成独立的动作
/ On our controller
public function actions()
{return ['qr' => ['class' => QrCodeAction::className(),'text' => 'https://2amigos.us','param' => 'v','commponent' => 'qr' // if configured in our app as `qr` ]];
}
在前端页面可以直接调用控制器
<img src="<?= Url::to(['controller/qr', 'v' => 'Hey! This is some content on my QrCode!']) ?>" /><!-- this will display https://2amigos.us (default text) -->
<img src="<?= Url::to(['controller/qr']) ?>" />
复杂的用法
// A label can be a string OR a Da\Contracts\LabelInterface instance.
// Using the instance, we will have more control on how do we want the label to be displayed.
// Immutability also applies to this class!
$label = (new Label('2amigos'))->setFont(__DIR__ . '/../resources/fonts/monsterrat.otf')->setFontSize(12);$qrCode = (new QrCode('https://2amigos.us'))->setLogo(__DIR__ . '/data/logo.png')->setForegroundColor(51, 153, 255)->setBackgroundColor(200, 220, 210)->setEncoding('UTF-8')->setErrorCorrectionLevel(ErrorCorrectionLevelInterface::HIGH)->setLogoWidth(60)->setSize(300)->setMargin(5)->setLabel($label);$qrCode->writeFile(__DIR__ . '/codes/my-code.png');
二维码Qrcode Library相关推荐
- java 生成二维码 QRCode、zxing 两种方式
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢. https://blog.csdn.net/testcs_dn/article/details/ ...
- Java实现二维码QRCode的编码和解码
涉及到的一些主要类库 编码lib:Qrcode_swetake.jar (官网介绍-- http://www.swetake.com/qr/index-e.html) ...
- 前端生成二维码qrcode.js,并下载
利用qrcode.js在前端生成二维码,并下载 一.引入js包 <script type="text/javascript" src="//static.runoo ...
- JAVA生成二维码QRcode
JAVA生成二维码QRcode 1 : 配置集成 1.1.配置maven 1.2.配置文件 1.3.logo文件 2 : 代码集成 2.1.加载配置文件 2.2.工具类 2.3.测试类 3 : 测试结 ...
- ZXing 生成二维码 QRCode 和条码 CODE128 和 ZXing 解析或读取 QR_Code 和 条码 CODE_128
二维码是国际标准,由日本某公司发明,并保留版权,免费让全世界使用,目前在中国金融支付领域大放异彩. 条码的联合发明人诺曼·约瑟夫·伍德兰德(Norman Joseph Woodland)于上世纪70年 ...
- 【免费】php 生成二维码 qrcode 源代码可在html直接调用
下载地址:qrcode.zip 使用phpqrcode生成二维码,可自定义内容,外边距,大小等.使用方便.调用简单. <?php header('content-type:image/png') ...
- Windows Phone 7 实战第二天 二维码QRcode
越来越多的收据具备自动对焦的拍摄功能,这也意味着这些手机可以具备条码扫描功能,手机具备条码扫描功能,可以优化购物流程,快速存储电子名片(二维码)等. QR 码是二维条码的一种,QR 来自英文 &quo ...
- 使用Qt绘制二维码 QRcode
--今天的我们,是站在巨人的肩膀上前行. 二维码自从出现以来,已经极大地改变了我们的生活方式,它能容纳一些简短的信息,却又不那么简短,以至于很多场合都能使用二维码作为信息的载体.一个月以前,有个老师跟 ...
- 使用 ABAP 代码制作手机能够扫描的二维码(QRCode)试读版
本专栏计划的文章数在 150 篇左右,到 2022年9月12日为止,目前已经更新了 51 篇,专栏完成度为 34% 零基础 ABAP 学习教程系列文章的目录 1. ABAP 标准培训教程 BC400 ...
最新文章
- php margin参数,margin参数简单介绍_html/css_WEB-ITnose
- Java1.8 帮助文档
- Google API 设计指南 - 前言
- MPU6050开发 -- Linux下测试
- python面向对象设计管理系统_python面向对象之单例设计模型
- 用Java处理大文件
- 【LeetCode】【HOT】142. 环形链表 II(快慢指针)
- 1200万!硅谷AI大牛一年赚够北京二环一套房
- Linux下安装Win10ARM,更多安卓旗舰机将可以安装运行Win10 ARM
- WebCollector
- 关于联想LJ2655DN出现open the frontcover then replace the toner的解决方法
- android参考文献 外文,android开发外文参考文献
- 在同一局域网如何共享文件
- 问题 B: 零基础学C/C++25——判断某整数是正整数、负整数还是零
- Windows软件推荐
- (Yuni)Markdown光速入门
- CENTOS上的网络安全工具(五)CODE来打个酱油
- php 生成国税局二维码
- JVM堆内存(新生代,老年代,Xms,Xmx)学习整理
- iPhone数据线连接电脑成为电脑USB摄像头
热门文章
- (转)redis常用命令及客户端的使用
- Android 实现自定义闹钟
- js给页面给某个id赋值_js 给元素id赋值
- 印象笔记无法连接服务器解决办法无法同步
- Linux命令进阶二
- 在Java版中被移除的物品,Java版已移除特性
- VoxEdit 创作比赛获奖者 NFT 集合上线市场平台
- php图片添加角标,我和极光的那些事儿 | 基于 PHPCordova — 推送实现及角标的设置...
- Wannacry(永恒之蓝)病毒
- 华人高管加入OpenAI;富士通发布AI平台;成都为鼓励AI产业发展提出19项资金扶持措施丨每日大事件...