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

PHP生成带LOGO的二维码图像

May 25, 2016 pm 04:39 PM

现在二维码是我们一些软件站或下载站常用的一种东西了,特别是微信都会使用二维码来加好友,下面我来介绍利用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="/static/imghw/default1.png"  data-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;"  class="lazy"   alt="QR code" widhtHeight="&#39;.$size.&#39;" widhtHeight="&#39;.$size.&#39;"/>&#39;;  
}
?>
Copy after login

生成像微信一样中间有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);
?>
Copy after login

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

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)