thinkphp3.2二维码扩展
//简易二维码
public function qrcode(){
Vendor('phpqrcode.phpqrcode');
//生成二维码图片
$object = new \QRcode();
$url='http://www.shouce.ren/';//网址或者是文本内容
$level=3;
$size=4;
$errorCorrectionLevel =intval($level) ;//容错级别
$matrixPointSize = intval($size);//生成图片大小
$object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
}
<?php
//高级使用带logo
public function qrcode(){
Vendor('phpqrcode.phpqrcode');
//生成二维码图片
$object = new \QRcode();
$qrcode_path='';
$file_tmp_name='';
$errors=array();
if(!empty($_POST)){
$content = trim($_POST['content']); //二维码内容
$contentSize=$this->getStringLength($content);
if($contentSize>150){
$errors[]='字数过长,不能多于150个字符!';
}
if(isset($_FILES['upimage']['tmp_name']) && $_FILES['upimage']['tmp_name'] && is_uploaded_file($_FILES['upimage']['tmp_name'])){
if($_FILES['upimage']['size']>512000){
$errors[]="你上传的文件过大,最大不能超过500K。";
}
$file_tmp_name=$_FILES['upimage']['tmp_name'];
$fileext = array("image/pjpeg","image/jpeg","image/gif","image/x-png","image/png");
if(!in_array($_FILES['upimage']['type'],$fileext)){
$errors[]="你上传的文件格式不正确,仅支持 png, jpg, gif格式。";
}
}
$tpgs=$_POST['tpgs'];//图片格式
$qrcode_bas_path='upload/qrcode/';
if(!is_dir($qrcode_bas_path)){
mkdir($qrcode_bas_path, 0777, true);
}
$uniqid_rand=date("Ymdhis").uniqid(). rand(1,1000);
$qrcode_path=$qrcode_bas_path.$uniqid_rand. "_1.".$tpgs;//原始图片路径
$qrcode_path_new=$qrcode_bas_path.$uniqid_rand."_2.".$tpgs;//二维码图片路径
if(Helper::getOS()=='Linux'){
$mv = move_uploaded_file($file_tmp_name, $qrcode_path);
}else{
//解决windows下中文文件名乱码的问题
$save_path = Helper::safeEncoding($qrcode_path,'GB2312');
if(!$save_path){
$errors[]='上传失败,请重试!';
}
$mv = move_uploaded_file($file_tmp_name, $qrcode_path);
}
if(empty($errors)){
$errorCorrectionLevel = $_POST['errorCorrectionLevel'];//容错级别
$matrixPointSize = $_POST['matrixPointSize'];//生成图片大小
$matrixMarginSize = $_POST['matrixMarginSize'];//边距大小
//生成二维码图片
$object::png($content,$qrcode_path_new, $errorCorrectionLevel, $matrixPointSize, $matrixMarginSize);
$QR = $qrcode_path_new;//已经生成的原始二维码图
$logo = $qrcode_path;//准备好的logo图片
if (file_exists($logo)) {
$QR = imagecreatefromstring(file_get_contents($QR));
$logo = imagecreatefromstring(file_get_contents($logo));
$QR_width = imagesx($QR);//二维码图片宽度
$QR_height = imagesy($QR);//二维码图片高度
$logo_width = imagesx($logo);//logo图片宽度
$logo_height = imagesy($logo);//logo图片高度
$logo_qr_width = $QR_width / 5;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
$from_width = ($QR_width - $logo_qr_width) / 2;
//重新组合图片并调整大小
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
$logo_qr_height, $logo_width, $logo_height);
//输出图片
//header("Content-type: image/png");
imagepng($QR,$qrcode_path);
imagedestroy($QR);
}else{
$qrcode_path=$qrcode_path_new;
}
}else{
$qrcode_path='';
}
}
$data=array('data'=>array('errors'=>$errors,'qrcode_path'=>$qrcode_path));
$this->assign('data',$data);
$this->display();
首先把扩展文件放进
https://files.cnblogs.com/files/zonglonglong/phpqrcode.rar

注意:如果在服务器上显示为空或异常,可以尝试使用ob_clean()或者ob_end_clean()
具体原因我也懒得查
thinkphp3.2二维码扩展的更多相关文章
- Yii 安装二维码扩展Qrcode
比如要添加 https://github.com/2amigos/yii2-qrcode-helper 生成二维码的 这个扩展第一种方法 : 1.打开根目录的composer.json, 在re ...
- Firefox 火狐网址生成二维码扩展推荐
该扩展并未在火狐官方的扩展站中上线,在火狐中国的站点中也几乎很难找到,只是作为火狐中国版的一个集成扩展. 各位想要使用该扩展,但又不愿安装火狐中国版的的浏览迷可以通过以下地址独立安装该扩展. 扩展地址 ...
- PHP 生成、识别二维码及安装相关扩展/工具
2018-02-20 00:30:26 更新:推荐新扩展(极力推荐) 这篇文章里用的两个二维码扩展都有些问题和麻烦:phpqrcode(生成二维码)的源码有点小 bug: 而 php-zbarcod ...
- Java与JS生成二维码
1.二维码概念 二维码/二维条码是用某种特定的集合图形按一定规律在平面上(二维方向上)分布的黑白相间的图形记录数据符号信息的图片. 黑线是二进制的1,空白的地方是二进制的0,通过1.0这种数据组合用于 ...
- PHP识别二维码(php-zbarcode)
PHP识别二维码(php-zbarcode) 标签: php二维码扩展 2015-11-06 17:12 609人阅读 评论(0) 收藏 举报 分类: PHP(1) Linux 版权声明:本文为博 ...
- Laravel5中通过SimpleQrCode扩展包生成二维码实例
Simple Qrcode是基于强大的Bacon/BaconQrCode库开发的针对Laravel框架的封装版本,用于在Laravel中为生成二维码提供接口. 安装SimpleQrCode扩展包 在项 ...
- thinkphp3.2集成QRcode生成二维码
一.下载QRcode源代码 https://sourceforge.net/projects/phpqrcode/files/releases/ 使用phpqrcode必须开启GD2扩展,phpqrc ...
- Spring Cloud OAuth2(二) 扩展登陆方式:账户密码登陆、 手机验证码登陆、 二维码扫码登陆
概要 基于上文讲解的spring cloud 授权服务的搭建,本文扩展了spring security 的登陆方式,增加手机验证码登陆.二维码登陆. 主要实现方式为使用自定义filter. Authe ...
- PHP生成二维码 endroid/qr-code 扩展包
目录 1. 引入 endroid/qr-code 扩展包 2. 使用示例 3. 二维码中放入logo,无法识别二维码的问题 1. 引入 endroid/qr-code 扩展包 https://pack ...
随机推荐
- c#操作ElasticSearch5详解
c#操作ElasticSearch详解 ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearc ...
- 3.第一个Node.js程序:Hello World!
转自:http://www.runoob.com/nodejs/nodejs-tutorial.html 以下是我们的第一个Node.js程序: console.log("Hello Wor ...
- python处理文件
打开文件: open是内建函数,一个方法 open("test.txt","r",buffering=1) test.txt 表示被打开的文件名,如果不 ...
- 从数据库中生成XML文件
前台页面<%@ page language="java" contentType="text/html; charset=utf-8" pageEncod ...
- 洛谷 P1893 山峰暸望
P1893 山峰暸望 题目描述 一天,Bessie在眺望美丽的威斯康星的群山的时候,她突然产生了疑问:那座山是最宽的? 她决定在地平线上,利用她的新式大量程山峰高度测量仪依次做N (1 <= N ...
- Android RecyclerView And CardView
Google I/O 2014大会公布Android L系统,还有Material Design全新的设计风格.而Material Design卡片式的设计.Google Play应用商店和G+ AP ...
- A glance on VDBI
Just like other thing in data transfter, a resource should have themselves description. And the reso ...
- C#程序集引入无效的解决方法
在项目类库中已经引用了相关了类库,生成解决方案也没问题,但是到了后置代码,通过using引用其他类库的时候,再生成解决方案或者生成单个类库,就会报“未能找到类型或命名空间“xxx"(是否缺少 ...
- Bootstrap时间控件常用配置项
1.给下面4个文本框初始化 $(function(){ $("#orderStartTime,#orderEndTime,#preSaleStartTime,#preSaleEndTim ...
- 利用formdata对象上传文件时,需要添加的参数
function doUpload() { var formData = new FormData($( "#uploadForm" )[0]); $.ajax({ url: 'h ...