Home >php教程 >php手册 >PHP生成带LOGO的二维码图像

PHP生成带LOGO的二维码图像

WBOY
WBOYOriginal
2016-05-25 16:39:491053browse

现在二维码是我们一些软件站或下载站常用的一种东西了,特别是微信都会使用二维码来加好友,下面我来介绍利用php生成二维码多种方法.

方法一,这种生成就是一个二维码中间不带图片的,直接调用google的一个功能就实现了,代码如下:

<?php
$urlToEncode="http://gz.altmi.com";  
generateQRfromGoogle($urlToEncode);  
function generateQRfromGoogle($chl,$widhtHeight =&#39;150&#39;,$EC_level=&#39;L&#39;,$margin=&#39;0&#39;) //开源代码phprm.com 
{  
    $url = urlencode($url);   
    echo &#39;<img src="http://chart.apis.google.com/chart?chs=&#39;.$widhtHeight.&#39;x&#39;.$widhtHeight.&#39;&cht=qr&chld=&#39;.$EC_level.&#39;|&#39;.$margin.&#39;&chl=&#39;.$chl.&#39;" alt="QR code" widhtHeight="&#39;.$size.&#39;" widhtHeight="&#39;.$size.&#39;"/>&#39;;  
}
?>

生成像微信一样中间有logo二维码,代码如下:

<?php
// QR Code + Logo Generator QR图片中间加logo 
$data = isset($_GET[&#39;data&#39;]) ? $_GET[&#39;data&#39;] : &#39;http://www.phprm.com&#39;; 
$size = isset($_GET[&#39;size&#39;]) ? $_GET[&#39;size&#39;] : &#39;130x130&#39;; 
$logo = isset($_GET[&#39;logo&#39;]) ? $_GET[&#39;logo&#39;] : &#39;./20130128160755.jpg&#39;;//中间那logo图 
$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(&#39;Content-type: image/png&#39;); 
imagepng($QR); 
imagedestroy($QR);
?>

最后分享一些常用的二维码生成插件下载地址

1,地址:http://phpqrcode.sourceforge.net/

下载:http://sourceforge.net/projects/phpqrcode/

2.libqrencode

地址:http://fukuchi.org/works/qrencode/index.en.html

php支持请参考:http://hirokawa.netflowers.jp/entry/4900/

3.QRcode Perl CGI & PHP scripts

地址:http://www.swetake.com/qr/qr_cgi.html


本文地址:

转载随意,但请附上文章地址:-)

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