hikarusun

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

发现了这个,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 二维码就这样生成了

分类:

技术点:

相关文章:

  • 2022-02-20
  • 2021-05-08
  • 2022-12-23
  • 2021-07-29
  • 2021-05-18
  • 2022-01-19
  • 2021-04-06
猜你喜欢
  • 2022-02-12
  • 2021-11-29
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案