php 生成二维码

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

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

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

代码以下:google

<?php
$urlToEncode="http://www.weste.net";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
{
 $url = urlencode($url);
 echo '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>';
}
?>url

生成的二维码图片:.net

\

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

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

demo代码以下:图片

<?
include "./phpqrcode/phpqrcode.php";
$value="http://www.weste.net";
$errorCorrectionLevel = "L";
$matrixPointSize = "4";
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
exit;
?>get

生成的二维码图片:

\

相关下载:PHP QR Code源码下载(二维码生成类库)

相关文章
相关标签/搜索