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

yipeiwu_com5年前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);
?>

相关文章

PHP7扩展开发之基于函数方式使用lib库的方法详解

本文实例讲述了PHP7扩展开发之基于函数方式使用lib库的方法。分享给大家供大家参考,具体如下: 前言 首先说下什么是lib库。lib库就是一个提供特定功能的一个文件。可以把它看成是PH...

PHP排序算法系列之直接选择排序详解

直接选择排序 直接选择排序(Straight Select Sorting) 的基本思想是:第一次从R[0]~R[n-1]中选取最小值,与R[0]交换,第二次从R[1]~R[n-1]中选...

php 函数使用可变数量的参数方法

php在用户自定义函数中支持可变数量的参数列表。 在php5.5及更早的版本中,使用func_num_args(), func_get_arg(), func_get_args()函数实...

php数组相加 array(“a”)+array(“b”)结果还是array(“a”)

在网上看到一道题: array("a")+array("b")的结果是___ A.array("a","b")B.array("b","a")C.array("b")D.array("a...

mcrypt启用 加密以及解密过程详细解析

Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。 1.PHP加密扩展库Mcrypt安装在标准的PHP安装过程中并没有把Mrcypt安装上,但PHP的主目录下包...