网络营销电子商务研究中心  
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

Reply
 
Thread Tools Display Modes
  #1   IP: 122.195.220.104
Old 2016-11-08, 01:23 PM
Mahtomedi Mahtomedi is offline
初级会员
 
Join Date: 2013-01-11
Posts: 1
Mahtomedi 现在声名狼藉
Default Php 生成二维码

在官网下载 phpqrcode.php就ok啦;
然后,查看自己的php环境是否开启GD2,若没有,开启支持即可;
利用 phpqrcode.php 的 function png() 方法便可生成最基本的二维码;
<?php
include 'phpqrcode.php';
$value = 'http://www.cheapglasses123.com/'; //二维码内容
QRcode:ng( $value );
?>
实际应用中,我们要在二维码的中间加上自己的LOGO。代码如下:
<?php
include 'phpqrcode.php'; // 引入phpqrcode.php
$value = 'http://www.cheapglasses123.com/'; // 要生成的二维码的内容
$errorCorrectionLevel = 'H'; // 容错级别
// L 7%的字码可被修正
// M 15%的字码可被修正
// Q 25%的字码可被修正
// H 30%的字码可被修正
$matrixPointSize = 10; // 生成图片大小
$img = "cheapglasses123.png"; // 生成图片的名字
//生成二维码图片
QRcode:ng( $value, $img, $errorCorrectionLevel, $matrixPointSize, 3 );
// 参数1 二维码的内容
// 参数2 生成二维码图片的名字
// 参数3 二维码识别的容错级别
// 参数4 生成二维码的图片的大小
// 参数5 二维码周围边框空白区域间距值
$logo = 'logo.png'; // 准备好的logo图片
$QR = $img; // 已经生成的原始二维码图
// 判断logo是否存在
if ($logo !== FALSE) {
$QR = imagecreatefromstring(file_get_contents($QR));
$logo = imagecreatefromstring(file_get_contents($logo));
$QR_width = imagesx($QR);//二维码图片宽度
$QR_height = imagesy($QR);//二维码图片高度
$logo_width = imagesx($logo);//logo图片宽度
$logo_height = imagesy($logo);//logo图片高度
$logo_qr_width = $QR_width / 4;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
$from_width = ($QR_width - $logo_qr_width) / 2;
//重新组合图片并调整大小
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
}
//输出图片
imagepng($QR, 'ok.png');
echo '<img src="ok.png">';
die();
?>
生成如下:
[img]http://www.0058.net/attachment.php?attachmentid=206&stc=1&d=1478582570
[/img]
Attached Images
File Type: jpg ok.jpg (200 KB, 1 views)

Last edited by Mahtomedi : 2016-11-08 at 01:25 PM
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 4 (0 members and 4 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
X-Cart Multiple Input Validation Holes Permit SQL Injection and Cross-Site Scripting topvip X-Cart 0 2009-07-21 10:03 AM
用php语言来编写shell脚本 car 代码交流 0 2008-05-05 08:09 PM
Php教程.经验技巧(上) sunshine 代码交流 0 2006-12-15 08:13 PM
Php入门速成 smiling 代码交流 0 2006-12-15 07:30 PM
php.ini中文解释 sunshine 服务器环境搭建 0 2006-02-04 11:05 PM

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


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