PHP generates QR code and adds logo between QR images_PHP tutorial

WBOY
Release: 2016-07-14 10:07:38
Original
1617 people have browsed it

When I wrote the QR code two years ago, no one knew it. Later, there were more software for scanning QR codes on mobile phones, and WeChat also changed this era.
Thanks to smartphones and WeChat.


================================================== ============
QR code is a type of two-dimensional barcode that can compile information such as website addresses, text, photos, etc. 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.

Two-dimensional bar code (dimensional bar code) uses a specific geometric figure to record data symbol information in black and white graphics distributed on a plane (in a two-dimensional direction) according to certain rules; it is cleverly used in code compilation. The concept of "0" and "1" bit streams, which form the basis of computer internal logic, uses several geometric shapes corresponding to binary to represent text numerical information, and automatically reads the information through image input equipment or photoelectric scanning equipment to achieve automatic information Processing: It has some common features of barcode technology: each code system has its own specific character set; each character occupies a certain width; it has certain verification functions, etc. At the same time, it also has the features of automatically identifying different lines of information and processing graphics rotation changes. Among many types of two-dimensional barcodes, commonly used code systems include: Data Matrix, Maxi Code, Aztec, QR Code, Vericode, PDF417, Ultracode, Code 49, Code 16K, etc. The QR code was developed by the Japanese company Denso-Wave in 1994. invention. QR comes from the abbreviation of "Quick Response" in English, which means quick response. It comes from the inventor's hope that the content of QR codes can be decoded quickly. QR codes are most common in Japan and South Korea; they are currently the most popular two-dimensional barcode in Japan.

<?php
 /**  * php生成二维码的2种方式
  * @author insun  */ //1.google开放api
 $urlToEncode="smart_insun";
 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;.$widhtHeight.&#39;" widhtHeight="&#39;.$widhtHeight.&#39;"/>';
 } //2.php类库PHP QR Code:http://phpqrcode.sourceforge.net/
 /* $data 数据
 $filename 保存的图片名称
 $errorCorrectionLevel 错误处理级别
 $matrixPointSize 每个黑点的像素
 $margin 图片外围的白色边框像素
 */ include "phpqrcode/qrlib.php";
 $data = "insun";
 $filename ="QR.jpg";
 $errorCorrectionLevel = 'L';
 $matrixPointSize = 2;
 $margin = 5;
 QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, $margin);//这样就生成了QR.jpg
 
Copy after login
 
Copy after login
Copy after login
php生成二维码的几种方式 - InSun - Minghacker is Insun


QR图片中间加logo
Copy after login

<?php
 /**  * QR Code + Logo Generator QR图片中间加logo,QR是根据google开放api生成的,其实啥都没有
   *    * http://labs.nticompassinc.com     */  //ini_set("auto_detect_line_endings", true);
  
  $data = isset($_GET[&#39;data&#39;]) ? $_GET[&#39;data&#39;] : &#39;http://weixin.qq.com/r/8bxsY6LEqpzVh7MAn_nV&#39;;
  $size = isset($_GET[&#39;size&#39;]) ? $_GET[&#39;size&#39;] : &#39;200x200&#39;;
  $logo = isset($_GET[&#39;logo&#39;]) ? $_GET[&#39;logo&#39;] : &#39;./logo.jpg&#39;;//中间那logo图
  // Get QR Code image from Google Chart API
  // http://code.google.com/apis/chart/infographics/docs/qr_codes.html
  //https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs=&#39;.$size.&#39;&chl=&#39;.urlencode($data));
  $png = "http://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=Hello+world&chld=L|1&choe=UTF-8";
  $QR = imagecreatefrompng($png);//Warning: imagecreatefrompng() [function.imagecreatefrompng]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? =
  //$QR = imagecreatefrompng(&#39;./chart.png&#39;);//外面那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);
          
   // Scale logo to fit in the QR Code
   $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;
   //echo $from_width;exit;
   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
 
Copy after login
Copy after login

Reference: QR
http://phpqrcode.sourceforge.net/

Introduction to the use of PHP QR Code, a class library for generating QR codes in PHP
http://www.BkJia.com/kf/201212/178526.html

https://developers.google.com/chart/infographics/docs/qr_codes?hl=zh-CN

http://ishare.iask.sina.com.cn/download/explain.php?fileid=23514545&page=2

There are several ways to generate QR code in php
http://blog.csdn.net/shojecom/article/details/8158571

http://www.qrhacker.com/
http://www.shadowdev.com/services/qr/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477849.htmlTechArticleNo one knew me when I wrote QR code two years ago. Later, there were more software for scanning QR codes on mobile phones, and WeChat also changed this era. Thanks to smartphones and WeChat. ==============...
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