自己搭建二维码接口

以前一直用别人现成的接口用着也不错,最近感觉有点卡,于是网上搜了一下。

发现了这个,phpqrcode 下载地址:http://sourceforge.net/projects/phpqrcode/

把他下载下来,里面有许多文件,我们只需要用到一个“phpqrcode.php”copy到自己的目录就行

接下来看怎么用。

同目录创建一个test.php

<?php 
//引入phpqrcode库文件
include('phpqrcode.php'); 
$value=$_GET['value']; // 二维码数据 $data = $value; // 生成的文件名 $filename = 'test.png'; // 纠错级别:L、M、Q、H $errorCorrectionLevel = 'L'; // 点的大小:1到10 $matrixPointSize = 4; //创建一个二维码文件 QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 4); //输入二维码到浏览器 QRcode::png($data);

 

ok这样就完成了,输入地址\test.php?value=xxxxxx二维码就这样生成了

不过发现个问题,phpqrcode既然不能设置图片的大小,网上搜了下有人给出了方法

打开phpqrcode.php,搜索

$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);

 然后这样修改一下

        //$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);

可以完成了,然后把test.php再修改一下

<?php 
//引入phpqrcode库文件
include('phpqrcode.php'); 
$value=$_GET['value'];
$width=$_GET['width'];
define('IMAGE_WIDTH', $width);
define('IMAGE_HEIGHT', $width);

// 二维码数据 
$data = $value; 
// 生成的文件名 
$filename = 'baidu.png'; 
// 纠错级别:L、M、Q、H 
$errorCorrectionLevel = 'L';  
// 点的大小:1到10 
$matrixPointSize = 4;  
//创建一个二维码文件 
QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 4);
//输入二维码到浏览器
QRcode::png($data); 

ok这下就真的完成了,输入地址\test.php?value=xxxxxx&width=500 二维码就这样生成了

转载于:https://www.cnblogs.com/hikarusun/p/4409656.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值