Home >php教程 >php手册 >php二维码生成支持logo(phpqrcode)

php二维码生成支持logo(phpqrcode)

WBOY
WBOYOriginal
2016-06-06 19:39:371138browse

根据phpqrcode官方原版修改 下载phpqrcode官方原版将api.php放到里面就行了 使用方法 http://域名/phpqrcode/api.php?data=二维码 ?phpheader("content-Type: text/html; charset=utf-8");$data =getdata('data');if(empty($data)){ $str="参数说明br / data

根据phpqrcode官方原版修改
下载phpqrcode官方原版将api.php放到里面就行了
使用方法
http://域名/phpqrcode/api.php?data=二维码

<?php
header("content-Type: text/html; charset=utf-8");
$data =getdata('data');if(empty($data)){
   $str="参数说明<br />
   data:要转码的数据<br />
   level:默认L 纠错级别:L、M、Q、H<br />
   size:默认4 点的大小:1到10,用于手机端4就可以了 <br />
   margin:默认1 边距 1到10 <br />
   logo:默认为空 中间logo 的文件名需要放到logo/目录中 <br /> 
   logosize:默认为5 中间logo 大小 1-10 数越小图越大.建议调高level值 <br /> 
   filename:默认为空 生成的文件名 生成后放到temp/目录中 <br />
   ";echo $str;exit;       
}
$level =getdata('level','L');//纠错级别:L、M、Q、H    
$size =getdata('size','4');//点的大小:1到10,用于手机端4就可以了
$margin =getdata('margin','1');//边距
$logo = getdata('logo');//logo
$filename=getdata('filename');// 生成的文件名
$logosize = getdata('logosize','5');//logo
$path = 'temp/';
if(!empty($filename)){$filename = $path.$filename.'_'.$size.'.png';
}else{$filename=false;}
if(!empty($logo) && empty($filename)){$filename = $path.$logo.'_'.$size.'.png';}$QR=false;
if(!empty($filename)){$QR=$path.basename($filename);}
include "qrlib.php";
$QRcode = new QRcode();
$QRcode->png($data,$QR,$level,$size,$margin);
if($logo){
    if(strpos($logo,'http://')===false)$logo='logo/'.$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_height = imagesy($logo);
    $logo_qr_width = $QR_width /$logosize;
    $scale = $logo_width / $logo_qr_width;
    $logo_qr_height = $logo_height / $scale;
    $from_width = ($QR_width - $logo_qr_width) / 2;
    $from_height = ($QR_height - $logo_qr_height) / 2;
    imagecopyresampled($QR, $logo, $from_width, $from_height, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
    header("Content-Type:image/jpg");
    imagepng($QR);exit;
}
if(!empty($filename))return $filename;
function getdata($name,$default=''){
$getdata=$_GET;
return empty($getdata[$name])?$default:$getdata[$name];
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn