网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站设计 > PHP
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   IP: 106.110.148.141
Old 2015-10-23, 07:10 PM
Hegins Hegins is offline
初级会员
 
Join Date: 2008-10-14
Posts: 1
Hegins 现在声名狼藉
Default php技术 生成二维码图片代码

我们可以看到到处是各种各样的二维码图片,甚至好多广告上打出:扫一扫此二维码图片有惊喜等活动;那么此项技术利用php怎样实现呢?



第一种方法:利用使用最广泛,最方便的Google api技术实现;





<?php

//1.封装生成二维码图片的函数(方法)

/** *利用google api生成二维码图片

* $content:二维码内容参数

* $size:生成二维码的尺寸,宽度和高度的值

* $lev:可选参数,纠错等级

* $margin:生成的二维码离边框的距离

*/

function create_erweima($content, $size = '100', $lev = 'L', $margin= '0') { $content = urlencode($content);

$image = '<img src="http://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&amp;cht=qr&chld='.$lev.'|'.$margin.'&amp;chl='.$content.'" widht="'.$size.'" height="'.$size.'" />';

return $image;

}



/* * 使用注意事项 * 1.先构建内容字符串 * 2.调用函数生成 */

//构建内容字符串

$content="吾倍吸干燥剂(AbsorbTech.cn)";

//调用函数生成二维码图片

echo create_erweima($content);

//纯文字型生成的图片如下图所示:


//把网址生成二维码;

$url="http://www.absorbtech.cn";

echo create_erweima($url);

?>


方法/步骤2


第二种方法使用php类库PHP QR Code;下载地址:http://phpqrcode.sourceforge.net

下载好解压,然后将phpqrcode文件夹拷贝(或复制)到项目中去;




<?php

//引入核心库文件

include "phpqrcode/phpqrcode.php";

//定义纠错级别

$errorLevel = "L";

//定义生成图片宽度和高度;默认为3

$size = "4";

//定义生成内容

$content="吾倍吸干燥剂(AbsorbTech.cn)";

//调用QRcode类的静态方法png生成二维码图片//

QRcode:ng($content, false, $errorLevel, $size);

//生成网址类型

$url="http://www.absorbtech.cn/";

QRcode:ng($url, false, $errorLevel, $size);

//示例代码下载地址:http://www.absorbtech.cn

?>
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:46 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.