~~~
<?php
namespace addons\qrcode\controller;
use Endroid\QrCode\QrCode;
use think\addons\Controller;
use think\Response;
/**
* 二维码生成
*
*/
class Index extends Controller
{
protected $model = null;
public function _initialize()
{
parent::_initialize();
}
public function index()
{
return $this->view->fetch();
}
// 生成二维码
public function build()
{
$text = $this->request->get('text', 'hello world');
$size = $this->request->get('size', 250);
$padding = $this->request->get('padding', 15);
$errorcorrection = $this->request->get('errorcorrection', 'medium');
$foreground = $this->request->get('foreground', "#ffffff");
$background = $this->request->get('background', "#000000");
$logo = $this->request->get('logo');
$logosize = $this->request->get('logosize');
$label = $this->request->get('label');
$labelfontsize = $this->request->get('labelfontsize');
$labelhalign = $this->request->get('labelhalign');
$labelvalign = $this->request->get('labelvalign');
// 前景色
list($r, $g, $b) = sscanf($foreground, "#%02x%02x%02x");
$foregroundcolor = ['r' => $r, 'g' => $g, 'b' => $b];
// 背景色
list($r, $g, $b) = sscanf($background, "#%02x%02x%02x");
$backgroundcolor = ['r' => $r, 'g' => $g, 'b' => $b];
$qrCode = new QrCode();
$qrCode
->setText($text)
->setSize($size)
->setPadding($padding)
->setErrorCorrection($errorcorrection)
->setForegroundColor($foregroundcolor)
->setBackgroundColor($backgroundcolor)
->setLogoSize($logosize)
->setLabel($label)
->setLabelFontSize($labelfontsize)
->setLabelHalign($labelhalign)
->setLabelValign($labelvalign)
->setImageType(QrCode::IMAGE_TYPE_PNG);
$fontPath = ROOT_PATH . 'public/assets/fonts/SourceHanSansK-Regular.ttf';
if (file_exists($fontPath)) {
$qrCode->setLabelFontPath($fontPath);
}
if ($logo) {
$qrCode->setLogo(ROOT_PATH . 'public/assets/img/qrcode.png');
}
//也可以直接使用render方法输出结果
//$qrCode->render();
return new Response($qrCode->get(), 200, ['Content-Type' => $qrCode->getContentType()]);
return $fontPath;
}
public function getimg(){
$url = "www.baidu.com";
$phone = "15555555555";
$domain = $this->request->domain();
$bigImgPath = $domain."/image/111.jpg";
$qCodePath = "http://ticket.cn/qrcode/build?text=http://".$url."&label=".$phone."&logo=1&labelhalign=0&labelvalign=3&foreground=%23ffffff&background=%23000000&size=90&padding=10&logosize=20&labelfontsize=11&errorcorrection=medium";
$bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));
list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);
imagecopymerge($bigImg, $qCodeImg, 330, 650, 0, 0, $qCodeWidth, $qCodeHight, 100);
list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);
header("Content-type: image/gif");
imagepng($bigImg);
die;
}
}
~~~
- tp5图片上传
- 文件上传到七牛云
- 上传到阿里云
- 富文本编辑器
- phpexcel和spreadsheet
- phpexcel导出
- phpexcel导入
- spreadsheet
- tp5_api接口
- 跨域请求
- JWT
- 图片和视频上传接口
- 验证码
- tp5小程序登录
- tp5小程序支付
- tp5基础架构
- 验证层
- 模型层Model
- 控制器构找
- tp5.0支付宝
- 海报二维码
- 轮播图
- echarts柱状图
- layui的图片弹窗
- p标签显示指定行数(全部)
- jquery和layerdate调用日期
- ajax发送文件和图片的坑啊
- JS日期点击上一天和下一天
- 百度分享js
- POST请求
- 商品数据表
- tp5.0支付宝最全
- tp5路由的坑
- 二维数组排序
- tp5模型分组group错误
- 二维变一维数组
- 无限树形结构
- json对象转数组
- 模型关联查询
- tp5的模型获取器和字段设定
- 经纬度获取距离排序