利用phpqrcode生成二维码实例代码

   QR码详细原理可以参考QR维基百科,中文版介绍比较少,英文版介绍很全面,推荐看英文版的。

  Description

  PHP QR Code is open source (LGPL) library for generating QR Code, 2-dimensional barcode. Based on libqrencode C library, provides API for creating QR Code barcode images (PNG, JPEG thanks to GD2). Implemented purely in PHP.

  Features

  •Supports QR Code versions (size) 1-40

  •Numeric, Alphanumeric, 8-bit and Kanji encoding.

  •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

  •Debug data dump, error logging, time benchmarking

  •Provided merge tool helps deploy library as a one file

  •new! API documentation

  •new! Over 30 detailed examples

  •100% Open Source, LGPL Licensed

  Demo

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

  Generate fixed size images

  * phpqrcode本身未提供固定大小二维码的设置,请参考 http://sourceforge.net/p/phpqrcode/discussion/1111884/thread/f739531a/

 代码如下  

--- original/phpqrcode/qrimage.php       2010-08-18 07:06:24.000000000 -0700
+++ qrimage.php 2012-07-13 00:51:57.000000000 -0700
@@ -86,10 +86,15 @@
                 }
             }
-            $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
-            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
+
+            $targetW = (defined('IMAGE_WIDTH') ? IMAGE_WIDTH : $imgW * $pixelPerPoint );
+            $targetH = (defined('IMAGE_HEIGHT') ? IMAGE_HEIGHT : $imgH * $pixelPerPoint );
+
+            $target_image =ImageCreate($targetW, $targetH);
+
+            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $targetW, $targetH, $imgW, $imgH);
             ImageDestroy($base_image);
             return $target_image;
         }
-    }
No newline at end of file
+    }

用法,设置生成的二维码宽高为 500px

define('IMAGE_WIDTH', 500);
define('IMAGE_HEIGHT', 500);
QRcode::png('http://www.111cn.net/)');

时间: 2024-08-21 06:19:05

利用phpqrcode生成二维码实例代码的相关文章

yii+phpqrcode生成二维码实例

以前我们讲过一些关于用phpqrcode生成二维码的文章,下面我们先列出来 php利用PHP QR Code生成二维码(带logo) PHP生成二维码(使用PHP QR Code二维码生成类库) 利用phpqrcode生成二维码实例代码 超简单PHP生成二维码实例 下面我们来讲讲yii整合phpqrcode生成二维码的实例. 1,先到官网下载包  http://phpqrcode.sourceforge.net/ 下载官网提供的类库后,只需要使用phpqrcode.php就可以生成二维码了,当然

超简单PHP生成二维码实例

PHP生成二维码的方式有多种,可以利用google开放的API,可以利用php QR Code类库生成,本文着重介绍使用php QR Code类库来生成二维码. 1.代码包下载地址:http://sourceforge.net/projects/phpqrcode/ 2.下载下来的压缩包里面有很多示例,可以自行研究,下面给出一个简单的使用案例:  代码如下 复制代码 include "phpqrcode/phpqrcode.php"; $data='http://www.111cn.n

asp.net中利用QRCode生成二维码代码

1.使用下面代码首先需要下载QRCode.DLL文件引用到你的项目中  代码如下 复制代码 //生成二维码代码 public string generateQRCode() {     //生成二维码     string filename = string.Empty;     string filepath = string.Empty;       string txt_qr = "需要生成二维码信息";     string qrEncoding = "Byte&qu

Android平台利用ZXING生成二维码图片

zxing是google的一个开源二维码项目,目前基本上和二维码打交道的东西,都会用到它. 最近项目中用到了android手机需要根据提供的字符串生成二维码图片,之前用zxing做过二维码解码,编码还没做过,看了一些demo都是用到了zxing的j2se包的内容,这个在android或者其他平台上显然无法实现,所以我们要利用zxing生成二维矩阵,然后根据android平台的提供的api来生成图片. /** * 用字符串生成二维码 * @param str * @author zhouzhe@l

jquery.qrcode插件生成二维码实例

如何使用 1.首先在页面中加入jquery库文件和qrcode插件.  代码如下 复制代码 <script type="text/javascript" src="jquery.js"></script>  <script type="text/javascript" src="jquery.qrcode.min.js"></script> 2.在页面中需要显示二维码的地方加入以

js生成二维码实例(真实有效)

js文件  qrcode.js   代码 /*from tccdn minify at 2014-6-4 14:59:43,file:/cn/c/c/qrcode.js*/ /** * @fileoverview * - Using the 'QRCode for Javascript library' * - Fixed dataset of 'QRCode for Javascript library' for support full-spec. * - this library has

PHP在线生成二维码(google api)的实现代码详解_php实例

通过google在线生成二维码的api在线生成二维码. 代码如下: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> &l

使用PHP生成二维码的两种方法(带logo图像)_php实例

一.利用Google API生成二维码  Google提供了较为完善的二维码生成接口,调用API接口很简单,以下是调用代码: $urlToEncode="http://www.jb51.net"; generateQRfromGoogle($urlToEncode); /** * google api 二维码生成[QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式] * @param string $chl 二维码包含的信息,可以是数字.字符.二进制信

php生成二维码图片方法汇总_php实例

第一种方法: 1,第一种方法:利用使用最广泛,最方便的Google api技术实现: 2 ,<?php //封装生成二维码图片的函数(方法) /* 利用google api生成二维码图片 $content:二维码内容参数 $size:生成二维码的尺寸,宽度和高度的值 $lev:可选参数,纠错等级 $margin:生成的二维码离边框的距离*/ function create_erweima($content, $size = '100', $lev = 'L', $margin= '0') { $