先安照路径放好如图。
简单使用无logo:
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); }
高级使用带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();
演示地址:http://www.shouce.ren/tool/qrcode
相关推荐
一款基于thinkphp3.2.3二次开发的电子商城(前后台)!
ThinkPHP 3.2.3 核心版 更新日志:2014-12-24 [数据库方面]数据库驱动完全用PDO重写;支持通用insertAll方法;改进参数绑定机制;主从分布式数据库连接改进;对Mongo的支持更加完善;[模型方面]模型类的诸多增强和...
1.此项目是基于Thinkphp3.2.3+easyui做的权限管理系统,所有后台管理系统均可基于此项目开发。 2.项目集成php反射自动生成API文档,通过访问http://你的IP或者域名/文件地址/tpcs/index.php/Api/Doc/index.html即可...
thinkPHP3.2.3使用Cron实现网站访问执行任务。
之前的thinkphp3.2.2上传多张图片功能在thinkphp3.2.3上实现
ThinkPHP3.2.3快速入门pdf
ThinkPHP3.2.3快速入门
免费thinkPHP3.2.3框架
这个ThinkPHP3.2.3完全开发手册.chm是我花了几个小时制作的
thinkphp3.2.3开发的内容管理系统thinkphp3.2.3开发的内容管理系统
采用ThinkPHP3.2.3框架开发网站快速入门登录示例源码。
ThinkPHP3.2.3带完全开发手册
一个留言板系统。采用ThinkPHP3.2.3框架、MySQL数据库,使用了验证码、自定义标签、自定义数据模型的自动生成和关联模型、数据分页显示、文件上传等。附详细过程说明文档。
thinkphp3.2.3写的简易cms(易扩展),整合了百度editor,图片、视频、附件的上传功能都好用。
基于ThinkPHP3.2.3的微信OAuth2.0微信网页授权
拥有众多的优秀功能和特性,经历了三年多发展的同时,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和 改进,众多的典型案例确保可以稳定用于商业以及门户级的开发。 ThinkPHP借鉴了国外很多优秀...