php调用google接口生成二维码示例

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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获取四位字母和数字的随机数的实现方法

那么我们知道在php中简单的四位数的纯数字验证可以用rand(1000,9999)就可以了,但如果我们要得到字母和数字的随机四位数,那我们该如何写函数呢?下面胡鹏博客在php资料栏目下给...

PHP中使用break跳出多重循环代码实例

复制代码 代码如下: $array = array(1,2,3,4,5,6);  for($i=0;$i<10;$i++){  foreach($array...

PHP gbk环境下json_dencode传送来的汉字

复制代码 代码如下: function ArrEncode($arr){ foreach($arr as $k=>$v){ if(is_array($v)){ $arr[$k] =...

php继承中方法重载(覆盖)的应用场合

本文实例分析了php继承中方法重载(覆盖)的应用场合。分享给大家供大家参考。具体分析如下: 方法重载(override)/覆盖——在什么情况下使用:当父类知道所有的子类都需要用到一个方法...

file_get_contents(&quot;php://input&quot;, &quot;r&quot;)实例介绍

file_get_contents(&quot;php://input&quot;, &quot;r&quot;)实例介绍

解释不清,直接上例子index.html复制代码 代码如下:  <form action="action.php" method="post" >  &l...