代码笔记 |
打赏<?php
/*** 生成二维码并且返回图片地址* @param $code*/function qrcode($code) {$annex = gws_main::load_config('system','annex');$filename=md5($code.'|4|4').'.png';$dir=substr($filename,0,1).DIRECTORY_SEPARATOR.substr($filename,0,4);gws_main::load_sys_class('QRcode', '', 0);gws_main::load_sys_func('dir');$upload_path = gws_main::load_config('system','upload_path');$file=$upload_path.'qrcode'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$filename;dir_create(dirname($file));if(file_exists($file)) return $annex[array_rand($annex)].'qrcode'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$filename;QRcode::png($code,$file,'H',4,2);$QR=$file;$logo = GUHANTAI_PATH.'statics/images/icon.png';//准备好的logo图片if ($logo !== FALSE) {$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);}//输出图片imagepng($QR,$file);return $annex[array_rand($annex)].'qrcode'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$filename;}?>
|