当前位置:Gxlcms > PHP教程 > php调用google接口生成二维码实例

php调用google接口生成二维码实例

时间:2021-07-01 10:21:17 帮助过:26人阅读

例子,调用google接口来实现二维码。


  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);//外面那QR图
  8. //以下是二维码生成的主要代码
  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. //销毁二维码图像
  24. imagedestroy($QR);
  25. ?>

人气教程排行