国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home 類庫(kù)下載 PHP類庫(kù) Generate QR code with picture

Generate QR code with picture

Oct 10, 2016 am 11:03 AM

I just started trying it myself, and it may not be easy for the masters to understand. I hope it will be useful.網(wǎng) Step: 1. Download the phpqrcode.php file in http://phpqrcode.sourceForge.net/, and then put it in your own project;

2, write code and introduce phpqrcode.php files to achieve generating two two seconds to generate two two files to generate two two files to achieve generating two seconds to generate two two two to generate two two files to generate two two files to achieve generating two seconds. QR code.

Code:

1. phpqrcode.php file (download)

2. Test code (erweima.app.php)

<?php
/*
 * 生成二維碼
 */ 
class ErweimaApp extends ShoppingbaseApp{
    
    function index()
    {
        $this->display(&#39;erweima.html&#39;);
    }

    /**  
     * @param string $chl 二維碼包含的信息,可以是數(shù)字、字符、二進(jìn)制信息、漢字。 
     不能混合數(shù)據(jù)類型,數(shù)據(jù)必須經(jīng)過(guò)UTF-8 URL-encoded 
     * @param int $widhtHeight 生成二維碼的尺寸設(shè)置 
     * @param string $EC_level 可選糾錯(cuò)級(jí)別,QR碼支持四個(gè)等級(jí)糾錯(cuò),用來(lái)恢復(fù)丟失的、讀錯(cuò)的、模糊的、數(shù)據(jù)。 
     * L-默認(rèn):可以識(shí)別已損失的7%的數(shù)據(jù) 
     * M-可以識(shí)別已損失15%的數(shù)據(jù) 
     * Q-可以識(shí)別已損失25%的數(shù)據(jù) 
     * H-可以識(shí)別已損失30%的數(shù)據(jù) 
     * @param int $margin 生成的二維碼離圖片邊框的距離 
     */
    function credit_qrcode() 
    { 
        include &#39;/includes/libraries/phpqrcode.php&#39;; 
        $value = isset($_POST[&#39;url&#39;]) ? $_POST[&#39;url&#39;] : &#39;http://www.baidu.com&#39;;
        //上傳圖片
        if (isset($_FILES[&#39;image&#39;]) && $_FILES[&#39;image&#39;][&#39;error&#39;] == 0 ){
            $image = $this->_upload_file(&#39;image&#39;, &#39;erweima/&#39;, date(&#39;YmdHis&#39;) . mt_rand(1000, 9999), &#39;index.php?app=credit&act=credit_qrcode&#39;);
            if ($image){
                $logo = $image;
            }
        }
        else
        { 
            $logo = SITE_URL . &#39;/themes/mall/default/styles/default/images/001.jpg&#39;;//準(zhǔn)備好的logo圖片 
        }
        $errorCorrectionLevel = &#39;H&#39;;//容錯(cuò)級(jí)別 
    $matrixPointSize = 8;//生成圖片大小 
    //生成二維碼圖片 
    QRcode::png($value, &#39;qrcode.png&#39;, $errorCorrectionLevel, $matrixPointSize, 2); 
    $QR = &#39;qrcode.png&#39;;//已經(jīng)生成的原始二維碼圖 
        
        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 / 5; 
            $scale = $logo_width/$logo_qr_width; 
            $logo_qr_height = $logo_height/$scale; 
            $from_width = ($QR_width - $logo_qr_width) / 2; 
            //重新組合圖片并調(diào)整大小 
            imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, 
            $logo_qr_height, $logo_width, $logo_height);  
        }
        //輸出圖片 
    imagepng($QR, &#39;helloweba.png&#39;); 
    echo &#39;<img  src="/static/imghw/default1.png"  data-src="helloweba.png"  class="lazy"   alt="Generate QR code with picture" >&#39;; 
    }
    
    /**
     * 上傳文件
     * @return mix false表示上傳失敗,空串表示沒(méi)有上傳,string表示上傳文件地址
     * $file_name 為上傳文件name
     * $path_name 為上傳路徑
     * $save_name 為保存文件名
     * $ret_url 為回調(diào)URL
     **/
    function _upload_file($file_name, $path_name, $save_name, $ret_url = &#39;index.php&#39;)
    {
        $file = $_FILES[$file_name];
        $message = array(
            &#39;1&#39; => &#39;上傳的文件超過(guò)了 php.ini 中 upload_max_filesize 選項(xiàng)限制的值。&#39;,
            &#39;2&#39; => &#39;上傳文件的大小超過(guò)了 HTML 表單中 MAX_FILE_SIZE 選項(xiàng)指定的值。&#39;,
            &#39;3&#39; => &#39;文件只有部分被上傳。&#39;
        );
        switch ($file[&#39;error&#39;])
        {
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
            case UPLOAD_ERR_PARTIAL:
            if ($ret_url)
            {
                $this->show_warning($message[$file[&#39;error&#39;]], &#39;go_back&#39;);
                return false;
            }
            else
            {
                return array(&#39;done&#39; => FALSE, &#39;msg&#39; => $message[$file[&#39;error&#39;]]);
            }
            break;
        }
        if ($file[&#39;error&#39;] != UPLOAD_ERR_OK)
        {
            return &#39;&#39;;
        }
        import(&#39;uploader.lib&#39;);
        $uploader = new Uploader();
        $uploader->allowed_type(IMAGE_FILE_TYPE);
        $uploader->addFile($file);
        if ($uploader->file_info() === false)
        {
            if ($ret_url)
            {
                $this->show_warning($uploader->get_error(), &#39;go_back&#39;, $ret_url);
                return false;
            }
            else
            {
                return array(&#39;done&#39; => FALSE, &#39;msg&#39; => $uploader->get_error());
            }
        }
        $uploader->root_dir(ROOT_PATH);
        return $uploader->save(&#39;data/files/mall/&#39;.$path_name, $save_name);
    }
}

3. Template file (erweima.html)

 <div style="height:100px;border:1px solid gray;text-align:center;padding-top:20px;">
        <form action="index.php?app=erweima&act=credit_qrcode" method="post" enctype="multipart/form-data">
               請(qǐng)輸入網(wǎng)址:<input type="text" name="url" ><br />
               圖片上傳:<input type="file" name="image"><br />
               <input type="submit" name="sbt" value="提交">
        </form>
 </div>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72