php调用google接口生成二维码示例
程序员文章站
2023-11-17 16:32:22
复制代码 代码如下:
<?php
$data = isset($_get['t']) ? $_get['t'] : 'http://www.xxx.com';
$size = isset($_get['size']) ? $_get['size'] : '150x150';
$logo = isset($_get['logo']) ? $_get['logo'] :"./image/logo.jpg";
$chl = urlencode($logo);
$png = "http://chart.googleapis.com/chart?chs=$size&cht=qr&chl=$chl&chld=l|1&choe=utf-8";
$qr = imagecreatefrompng($png);//外面那qr图
if ($logo !== false) {
$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/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);
imagedestroy($qr);
?>
复制代码 代码如下:
<?php
$data = isset($_get['t']) ? $_get['t'] : 'http://www.xxx.com';
$size = isset($_get['size']) ? $_get['size'] : '150x150';
$logo = isset($_get['logo']) ? $_get['logo'] :"./image/logo.jpg";
$chl = urlencode($logo);
$png = "http://chart.googleapis.com/chart?chs=$size&cht=qr&chl=$chl&chld=l|1&choe=utf-8";
$qr = imagecreatefrompng($png);//外面那qr图
if ($logo !== false) {
$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/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);
imagedestroy($qr);
?>
上一篇: 采用MATLAB画三维曲线的教程