PHP生成二维图型码

来源:互联网 发布:mac照片导入ipad 编辑:程序博客网 时间:2024/06/05 10:09

1.利用Google的API生成二维码

<?php$urlToEncode = "http://www.eotao.com";generateQRfromGoogle ( $urlToEncode );/** * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 * @param string $chl 二维码包含的信息,可以是数字、字符、二进制信息、汉字。不能混合数据类型,数据必须经过UTF-8 URL-encoded.如果需要传递的信息超过2K个字节,请使用POST方式 * @param int $widhtHeight 生成二维码的尺寸设置 * @param string $EC_level 可选纠错级别,QR码支持四个等级纠错,用来恢复丢失的、读错的、模糊的、数据。 * L-默认:可以识别已损失的7%的数据 * M-可以识别已损失15%的数据 * Q-可以识别已损失25%的数据 * H-可以识别已损失30%的数据 * @param int $margin 生成的二维码离图片边框的距离 */function generateQRfromGoogle($chl, $widhtHeight = '150', $EC_level = 'L', $margin = '0') {$chl = urlencode ( $chl );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="' . $widhtHeight . '" widhtHeight="' . $widhtHeight . '"/>';}


2.利用PHP二维条形码开发包 PHP QR Code

PHP QR Code 是 PHP 用来处理二维条形码的开发包。基于 C 语言的 libqrencode 库开发,提供生成二维条形码功能,包括 PNG、JPG 格式。使用纯 PHP 实现,无需依赖第三方包,除了 GD2 除外。

主要特性:

  • Supports QR Code versions (size) 1-40
  • Numeric, Alphanumeric, 8-bit and Kanji encoding. (Kanji encoding was not fully tested, if you are japan-encoding enabled you cen contribute by verifing it :) )
  • Implemented purely in PHP, no external dependencies except GD2
  • Exports to PNG, JPEG images, also exports as bit-table
  • TCPDF 2-D barcode API integration
  • Easy to configure
  • Data cache for calculation speed-up
  • Provided merge tool helps deploy library as a one big dependency-less file, simple to "include and do not wory"
  • Debug data dump, error logging, time benchmarking
  • 100% Open Source, LGPL Licensed

示例代码:

QRcode::png('code data text', 'filename.png'); // creates fileQRcode::png('some othertext 1234'); // creates code image and outputs it directly into browser

项目地址: http://phpqrcode.sourceforge.net/