zoukankan      html  css  js  c++  java
  • PHP生成二维码


    createQrcode.php

    
    <?php
    
    /**
     * composer 安装 composer require aferrandini/phpqrcode
     */
     
    /**
    * 二维码生成
    * Time:2018/7/20 0020
    */
    public function createQrcode(){
    	$id=input('id');
    	$url = 'http://' . $_SERVER['HTTP_HOST'] . '/index/user/center?car_id=' . $id;
    //		$res = create_qrcode($id,$url,'car');  //生成不带logo的二维码
    	$res = create_png($url, true, './uploads/qrcode/car/car_'.$id.'.png', 'H');  //生成带logo的二维码
        $re = $this->logicCar->editField($id,'qrcode',$res);
        $this->ajaxJump($re);
    }/**二维码生成器
     * User:wanglu
     * Time:2018/7/20 0020
     * @param $id
     * @return bool|string
     */
    
    function create_qrcode($id, $url, $model)
    {
        $pash = './uploads/qrcode/'.$model.'/'.$model.'_' . $id . '.png';
        if (!file_exists(dirname($pash))){
            mkdir(dirname($pash),0777,true);
        }
        if(file_exists($pash)){
            unlink($pash);
        }
        PHPQRCodeQRcode::png($url, $pash, 'H', 10,2);
        $path = substr($pash, 1);
    
        return $path;
    }
    
    /**
     * 生成带logo的二维码
     * @param $text         二维码内容
     * @param bool $logo    是否带log
     * @param bool $outfile 输出地址
     * @param string $level 容错等级
     * @param int $size     尺寸
     * @param int $margin   边框
     * @param bool $saveandprint
     * @return bool|string
     * User: Dh106
     * Date: 2018/8/10
     * Time: 9:16
     */
    function create_png($text, $logo = false, $outfile = false, $level = 'H', $size = 10, $margin = 2, $saveandprint=false)
    {
        if ( $outfile ) {
            if (!file_exists(dirname($outfile))){
                mkdir(dirname($outfile),0777,true);
            }
            PHPQRCodeQRcode::png($text, $outfile, $level, $size, $margin, $saveandprint);
            $QR = file_get_contents($outfile);
        } else {
            ob_start();
            PHPQRCodeQRcode::png($text, $outfile, $level, $size, $margin, $saveandprint);
            $QR = ob_get_contents();
            ob_end_clean();
        }
        $logopath = ROOT_PATH.'public/static/platform/images/yycxlogo.png';
    
        //合并logo
        if ( $logo !== false && $logo = file_get_contents($logopath) ) {
            $QR = imagecreatefromstring($QR);
            $logo = imagecreatefromstring($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;
            // imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
    
            //logo不失真
            $dstX = $QR_width/2 - $logo_width/2;
            $dstY = $QR_width/2 - $logo_width/2;
            imagecopyresampled($QR, $logo, $dstX, $dstY, 0, 0, $logo_width, $logo_height, $logo_width, $logo_height);
    
            if ( $outfile ) {
                imagepng($QR, $outfile);
            } else {
                ob_start();
                imagepng($QR);
                ob_get_contents();
                ob_end_clean();
            }
        }
    
        return substr($outfile,1);
    }
    
    
  • 相关阅读:
    洛谷P3258 [JLOI2014]松鼠的新家
    洛谷P3128 [USACO15DEC]最大流Max Flow
    Bzoj1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
    2017-9-26 NOIP模拟赛
    洛谷P1441 砝码称重
    洛谷P1275 魔板
    洛谷P2037 电话号码
    2014-11-3 NOIP模拟赛2
    洛谷P3102 [USACO14FEB]秘密代码Secret Code
    洛谷P3070 [USACO13JAN]岛游记Island Travels
  • 原文地址:https://www.cnblogs.com/qixidi/p/10206078.html
Copyright © 2011-2022 走看看