发布时间:2019年04月30日 16:20:23编辑:admin阅读(1867)评论(0)
使用二维码的时候,除了内容外,还是需要对二维码进行一定的设置,比如二维码的大小,颜色,边框等;还有logo的添加,logo的大小等。二维码图片存放位置等。
前提:保存二维码需要给二维码个路径,需要logo的话,还要提供logo的路径。
安排:
/* $qrcode_name 二维码加密内容 $qrcode_url 生成的二维码保存地址 */ public function set_qrcode($qrcode_name,$qrcode_url) { header("Content-Type: text/html;charset=utf-8"); //logo $logo = ''; $system = db('system')->where('name','qr_code')->find(); $logo_url = db('system')->where('name','qrcode_url')->find(); if(!empty($system) && $system['value']==1){ if(empty($logo_url) || empty($logo_url['value'])) return '二维码开启了logo,没有上传logo图片,请在系统设置内设置'; else $logo = substr($logo_url['value'],1); } Vendor('phpqrcode.phpqrcode'); $object = new \QRcode(); //二维码内容 $url = $qrcode_name; //容错级别 $errorCorrectionLevel = 'L'; //生成图片大小 $matrixPointSize = 6; //生成一个二维码图片 $object->png($url, $qrcode_url, $errorCorrectionLevel, $matrixPointSize, 2); //准备好的logo图片,本人放在了根目录下 //$logo = 'public/timg.jpg'; //已经生成的原始二维码图,也在根目录下 //$qrcode = 'public/qrcode.jpg'; //logo图片存在 if (file_exists($logo)) { $set_qrcode = imagecreatefromstring(file_get_contents($qrcode_url)); $logo = imagecreatefromstring(file_get_contents($logo)); $qrcode_width = imagesx($set_qrcode); //二维码图片宽度 $qrcode_height = imagesy($set_qrcode); //二维码图片高度 $logo_width = imagesx($logo); //logo图片宽度 $logo_height = imagesy($logo); //logo图片高度 $logo_qr_width = $qrcode_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($qrcode_width - $logo_qr_width) / 2; //重新组合图片并调整大小 imagecopyresampled($set_qrcode, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); } //输出图片 imagepng($qrcode_url, $qrcode_url); return true; }
上一篇: 新手简单发送邮件
下一篇: js 基础简单正则表达式
8047
5296
5309