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中冒号、endif、endwhile、endfor使用介绍

我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如: 复制代码 代码如下: <?php if(empty($GET_['a'])): ?> &l...

解析php通过cookies获取远程网页的指定代码

复制代码 代码如下:function Steal($url, $post_data = ""){//$header[] = "Accept: text/vnd.wap.wml,*.*";...

WordPress主题制作中自定义头部的相关PHP函数解析

header_image() header_image() 函数是 WordPress 自定顶部图像的标准接口函数,该函数可以自动判断后台设置,并返回字符串形式的用户自定义顶部图像地址。...

PHP中用接口、抽象类、普通基类实现“面向接口编程”与“耦合方法”简述

复制代码 代码如下: <?php /* 边学边做的,为方便自己翻阅而发布,更为得到高人指点而发布,欢迎高手指点...... 【提示】本例通过测试无误 【情景设计】 模拟计算机主板I...

浅谈PHP中类和对象的相关函数

浅谈PHP中类和对象的相关函数

class_exists 判断一个类是否存在,参数为一个名字! interface_exists 判断一个接口是否存在,参数也是为一个名字! method_exists 判断一个方...