zoukankan      html  css  js  c++  java
  • 自己搭建二维码接口

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

    发现了这个,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这样就完成了,输入地址 est.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这下就真的完成了,输入地址 est.php?value=xxxxxx&width=500 二维码就这样生成了

  • 相关阅读:
    [HAOI2016]食物链
    [TJOI2011]序列
    P2548 [AHOI2004]智能探险车
    [JSOI2008]最大数
    模板之dinic
    Excim的NOIP2017游记
    数列排序
    Car的旅行路线
    [HAOI2006]均分数据
    [luogu2210] Haywire
  • 原文地址:https://www.cnblogs.com/hikarusun/p/4409656.html
Copyright © 2011-2022 走看看