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

  • 相关阅读:
    window 窗口对象 Javascript语言描述
    ASP.NET JScript公共类(非常有用)
    ASP.NET上传文件函数
    C#两种方式获取指定文件夹下所有子目录及文件
    模式窗口showModalDialog的用法总结
    DetailsView结合fileupload的使用
    JS连续向上滚动代码
    【原创】C# 递归获取指定目录的子目录及其所有文件
    【原创】C# 将虚拟目录下文件转换成DataTable
    【原创】ASP.NET C# 获取指定目录文件的排序和删除
  • 原文地址:https://www.cnblogs.com/hikarusun/p/4409656.html
Copyright © 2011-2022 走看看