PHP多文字,二维码(动态(支持带logo)、非动态)生成海报方式
1.下载二维码插件Phpqrcode,地址 [https://sourceforge.net/projects/phpqrcode/files/]
//动态二维码方式
function create_qrcode($data,$img)
{
require APP_PATH . MODULE_NAME . '/View/Public/phpqrcode/phpqrcode.php';
$outfile=APP_PATH . MODULE_NAME . '/View/Public/images/qrcode/111.jpg';
$level = 'L';
$size =6;
$QRcode = new \QRcode();
ob_start();
$QRcode->png($data,$outfile,$level,$size,2);
ob_end_clean();
// $logo = './uploads/imgs/111.jpg';//准备好的logo图片
// $QR = $outfile;//已经生成的原始二维码图
// 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);
// }
// $outfile="./uploads/imgs/".$img.'.jpg';
// imagepng($QR, "./uploads/imgs/".$img.'.jpg');
return $outfile;
}
/**
*生成宣传海报
*@param array 参数,包括图片和文字
*@param string $filename 生成海报文件名,不传此参数则不生成文件,直接输出图片
*@return [type] [description]
*/
function createPoster($config=array(),$filename="")
{
//如果要看报什么错,可以先注释调这个header
if(empty($filename)) {
header("content-type: image/png");
}
$imageDefault = array(
'left'=>0,
'right'=>0,
'bottom'=>0,
'width'=>100,
'height'=>100,
'opacity'=>100
);
$textDefault = array(
'text'=>'',
'left'=>0,
'fontSize'=>32, //字号
'fontColor'=>'255,255,255', //字体颜色
'angle'=>0,
);
$background = $config['background'];//海报最底层得背景
//背景方法