Home > Backend Development > PHP Tutorial > PHP calls google interface to generate QR code example

PHP calls google interface to generate QR code example

WBOY
Release: 2016-07-25 09:13:23
Original
840 people have browsed it
For example, call the Google interface to implement the QR code.


  1. ?php
  2. $data = isset($_GET['t']) ? $_GET['t'] : 'http://www.XXX.com';
  3. $size = isset($_GET['size']) ? $_GET['size'] : '150x150';
  4. $logo = isset($_GET['logo']) ? $_GET['logo'] : "./ image/logo.jpg";
  5. $chl = urlencode($logo);
  6. $png = "http://chart.googleapis.com/chart?chs=$size&cht=qr&chl=$chl&chld=L|1&choe= UTF-8";
  7. $QR = imagecreatefrompng($png);//The QR image outside
  8. //The following is the main code for QR code generation
  9. if ($logo !== FALSE) {
  10. $ logo = imagecreatefromstring(file_get_contents($logo));
  11. $QR_width = imagesx($QR);
  12. $QR_height = imagesy($QR);
  13. $logo_width = imagesx($logo);
  14. $logo_height = imagesy ($logo);
  15. $logo_qr_width = $QR_width/5;
  16. $scale = $logo_width/$logo_qr_width;
  17. $logo_qr_height = $logo_height/$scale;
  18. $from_width = ($QR_width-$logo_ qr_width)/ 2;
  19. imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
  20. }
  21. header('Content-type: image/png ');
  22. imagepng($QR);
  23. //Destroy the QR code image
  24. imagedestroy($QR);
  25. ?>
Copy code


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