Home > Backend Development > PHP Tutorial > PHP generates QR code implementation code

PHP generates QR code implementation code

巴扎黑
Release: 2016-11-21 13:30:05
Original
1167 people have browsed it

QR code is a type of two-dimensional barcode. It can compile website addresses, text, photos and other information into a square barcode pattern through corresponding encoding algorithms. Mobile phone users can re-decode the relevant information and view the content through the camera and decoding software.
php class library PHP QR Code
# Two sentence explanation:
# If it contains qrlib.php, it needs to be placed together with other files: files and folders.
# phpqrcode.php is the merged version, you only need to include this file, but the generated image is slow and inaccurate
# Two usages are given below:

<?php 
   include(&#39;./phpqrcode/phpqrcode.php&#39;); 
   // 二维码数据 
   $data = &#39;http://gz.altmi.com&#39;; 
   // 生成的文件名 
   $filename = $errorCorrectionLevel.&#39;|&#39;.$matrixPointSize.&#39;.png&#39;; 
   // 纠错级别:L、M、Q、H 
   $errorCorrectionLevel = &#39;L&#39;;  
   // 点的大小:1到10 
   $matrixPointSize = 4;  
   QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
?>
  
# 创建一个二维码文件 
QRcode::png(&#39;code data text&#39;, &#39;filename.png&#39;); 
// creates file 
  
# 生成图片到浏览器 
QRcode::png(&#39;some othertext 1234&#39;); 
// creates code image and outputs it directly into browser
Copy after login

If you generate colorful ones, you need to do it yourself
Modify phpqrcode. The code for the color setting part of the image method of the QRimage class in php. The code for version 1.1.4 is at lines 987 and 988. One foreground color and one background color:

$col[0] = ImageColorAllocate($base_image,255,255,255);
$col[1] = ImageColorAllocate($base_image,0,0,0);
Copy after login

Just
generate using Google’s open api

$urlToEncode="http://gz.altmi.com"; 
generateQRfromGoogle($urlToEncode); 
function generateQRfromGoogle($chl,$widhtHeight =&#39;150&#39;,$EC_level=&#39;L&#39;,$margin=&#39;0&#39;) 
{ 
    $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;; 
}
Copy after login


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