Home > Backend Development > PHP Tutorial > PHP generates QR code image with LOGO_PHP tutorial

PHP generates QR code image with LOGO_PHP tutorial

WBOY
Release: 2016-07-20 11:11:34
Original
932 people have browsed it

Nowadays, QR codes are commonly used in some of our software sites or download sites. In particular, WeChat uses QR codes to add friends. Now I will introduce various methods of using PHP to generate QR codes.

Method 1 This kind of generation is a QR code without a picture in the middle. It can be realized by directly calling a function of Google.

The code is as follows
 代码如下 复制代码

$urlToEncode="http://gz.altmi.com";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
{
    $url = urlencode($url); 
    echo 'QR code';
}

Copy code


$urlToEncode="http://gz.altmi.com";
 代码如下 复制代码

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

generateQRfromGoogle($urlToEncode);

function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level= 'L',$margin='0')
{

$url = urlencode($url);

echo 'QR code';
}


Generate like WeChat There is a logo QR code in the middle

// QR Code + Logo Generator Add logo in the middle of the QR image
The code is as follows
Copy code
$data = isset($_GET['data']) ? $_GET['data'] : 'http://www.hzhuti.com';
$size = isset($_GET['size']) ? $_GET['size'] : '130x130';$logo = isset($ _GET['logo']) ? $_GET['logo'] : './20130128160755.jpg';//The logo picture in the middle

$png = "http://chart.googleapis.com/chart?chs=$size&cht=qr&chl=$chl&chld=L|1&choe=UTF-8";$QR = imagecreatefrompng($png);// The QR image outsideif ($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); Finally share the download address of some commonly used QR code generation plug-ins Address: http://phpqrcode.sourceforge.net /Download: http://sourceforge.net/projects/phpqrcode/3.libqrencodeAddress: http://fukuchi.org/works/qrencode/index.en .htmlPHP support please refer to: http://hirokawa.netflowers.jp/entry/4900/4.QRcode Perl CGI & PHP scriptsAddress: http://www.swetake .com/qr/qr_cgi.html http://www.bkjia.com/PHPjc/444625.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444625.htmlTechArticleNow QR code is a commonly used thing in some of our software sites or download sites, especially WeChat. Use QR code to add friends. Below I will introduce various methods to generate QR code using php...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template