Home  >  Article  >  php教程  >  二维码在线生成图片PHP源代码

二维码在线生成图片PHP源代码

WBOY
WBOYOriginal
2016-06-13 09:29:341116browse

二维码在线生成图片PHP源代码

   二维码现在变得越来越流行了,这里介绍两端PHP的二维码生成代码,一段使用了Google开放的二维码API,另一段使用的是PHP QR Code二维码开源类库,都很简单。

  1、使用Google Chart API生成二维码图片

  Google Chart API是一个功能十分强大的API,生成二维码仅仅是其中的一个小功能。这里只介绍二维码部分,如果想了解更多功能,可以登录官网地址:http://code.google.com/intl/zh-CN/apis/chart/

  代码如下:

  

  $urlToEncode="http://www.weste.net";

  generateQRfromGoogle($urlToEncode);

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

  {

  $url = urlencode($url);

  echo '';

  }

  ?>

  生成的二维码图片:

  2、使用PHP QR Code生成二维码图片

  PHP QR Code是一个开源的php二维码开源类库,基于libqrencode C库,并提供API代码创建QR条码图像,支持png、jpg格式。功能强大,使用起来也非常简单。

  demo代码如下:

  

  include "./phpqrcode/phpqrcode.php";

  $value="http://www.weste.net";

  $errorCorrectionLevel = "L";

  $matrixPointSize = "4";

  QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);

  exit;

  ?>

  生成的二维码图片:

Statement:
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