Home Backend Development PHP Tutorial ThinkPHP3.2.3扩张之二维码

ThinkPHP3.2.3扩张之二维码

Jun 13, 2016 pm 12:28 PM
errors logo path width

ThinkPHP3.2.3扩展之二维码

先安照路径放好如图。

简单使用无logo:

public function qrcode(){        Vendor('phpqrcode.phpqrcode');        //生成二维码图片        $object = new \QRcode();        $url='http://www.shouce.ren/';//网址或者是文本内容        $level=3;        $size=4;        $errorCorrectionLevel =intval($level) ;//容错级别        $matrixPointSize = intval($size);//生成图片大小        $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);    }
Copy after login

高级使用带logo:

public function qrcode(){        Vendor('phpqrcode.phpqrcode');        //生成二维码图片        $object = new \QRcode();        $qrcode_path='';        $file_tmp_name='';        $errors=array();        if(!empty($_POST)){            $content = trim($_POST['content']); //二维码内容            $contentSize=$this->getStringLength($content);            if($contentSize>150){                $errors[]='字数过长,不能多于150个字符!';            }            if(isset($_FILES['upimage']['tmp_name']) && $_FILES['upimage']['tmp_name'] && is_uploaded_file($_FILES['upimage']['tmp_name'])){                if($_FILES['upimage']['size']>512000){                    $errors[]="你上传的文件过大,最大不能超过500K。";                }                $file_tmp_name=$_FILES['upimage']['tmp_name'];                $fileext = array("image/pjpeg","image/jpeg","image/gif","image/x-png","image/png");                if(!in_array($_FILES['upimage']['type'],$fileext)){                    $errors[]="你上传的文件格式不正确,仅支持 png, jpg, gif格式。";                }            }            $tpgs=$_POST['tpgs'];//图片格式            $qrcode_bas_path='upload/qrcode/';            if(!is_dir($qrcode_bas_path)){                mkdir($qrcode_bas_path, 0777, true);            }            $uniqid_rand=date("Ymdhis").uniqid(). rand(1,1000);            $qrcode_path=$qrcode_bas_path.$uniqid_rand. "_1.".$tpgs;//原始图片路径            $qrcode_path_new=$qrcode_bas_path.$uniqid_rand."_2.".$tpgs;//二维码图片路径            if(Helper::getOS()=='Linux'){                $mv = move_uploaded_file($file_tmp_name, $qrcode_path);            }else{                //解决windows下中文文件名乱码的问题                $save_path = Helper::safeEncoding($qrcode_path,'GB2312');                if(!$save_path){                    $errors[]='上传失败,请重试!';                }                $mv = move_uploaded_file($file_tmp_name, $qrcode_path);            }            if(empty($errors)){                $errorCorrectionLevel = $_POST['errorCorrectionLevel'];//容错级别                $matrixPointSize = $_POST['matrixPointSize'];//生成图片大小                $matrixMarginSize = $_POST['matrixMarginSize'];//边距大小                //生成二维码图片                $object::png($content,$qrcode_path_new, $errorCorrectionLevel, $matrixPointSize, $matrixMarginSize);                $QR = $qrcode_path_new;//已经生成的原始二维码图                $logo = $qrcode_path;//准备好的logo图片                if (file_exists($logo)) {                    $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;                    //重新组合图片并调整大小                    imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,                    $logo_qr_height, $logo_width, $logo_height);                    //输出图片                    //header("Content-type: image/png");                    imagepng($QR,$qrcode_path);                    imagedestroy($QR);                }else{                    $qrcode_path=$qrcode_path_new;                }            }else{                $qrcode_path='';            }        }        $data=array('data'=>array('errors'=>$errors,'qrcode_path'=>$qrcode_path));        $this->assign('data',$data);        $this->display();
Copy after login

演示地址:http://www.shouce.ren/tool/qrcode

用到助手类Helper地址:http://www.thinkphp.cn/topic/34875.html

  

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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

Steps to set the PATH environment variable of the Linux system Steps to set the PATH environment variable of the Linux system Feb 18, 2024 pm 05:40 PM

How to set the PATH environment variable in Linux systems In Linux systems, the PATH environment variable is used to specify the path where the system searches for executable files on the command line. Correctly setting the PATH environment variable allows us to execute system commands and custom commands at any location. This article will introduce how to set the PATH environment variable in a Linux system and provide detailed code examples. View the current PATH environment variable. Execute the following command in the terminal to view the current PATH environment variable: echo$P

What does the width of html mean? What does the width of html mean? Jun 03, 2021 pm 02:15 PM

In HTML5, width means width. The width attribute defines the width of the element's content area. You can add inner margins, borders, and outer margins outside the content area. You only need to set "element {width: value}" to the element.

How to set the path environment variable How to set the path environment variable Sep 04, 2023 am 11:53 AM

Method to set the path environment variable: 1. Windows system, open "System Properties", click the "Properties" option, click "Advanced System Settings", in the "System Properties" window, select the "Advanced" tab, and then click "Environment Variables" " button, find and click "Path" to edit and save; 2. For Linux systems, open the terminal, open your bash configuration file, add "export PATH=$PATH: file path" at the end of the file and save it; 3. For MacOS system, the operation is the same as above.

Foton Motor releases new logo and price information of Xiangling Q series models Foton Motor releases new logo and price information of Xiangling Q series models Sep 12, 2023 pm 09:09 PM

On August 29, Foton Motor held a gorgeous brand refresh conference, bringing a series of exciting news to the industry. The new logo, Auman Zhilan bottom battery replacement products and the new Xiangling Q car became the focus of the press conference. Foton Motor's new logo shows the company's ambitions for the future. Foton Motor said that this new logo symbolizes the renewal and vigorous development of the brand, marking the company's entry into a new stage of development. At the press conference, Foton Motor also launched the much-anticipated Auman Smart Blue bottom battery replacement product to bring users Here comes a more convenient and efficient use experience. At the same time, the newly launched Xiangling Q car series has also attracted a lot of attention. There are 4 models in total, with prices ranging from 167,800 yuan to 168,800 yuan, providing consumers with

How to configure path environment variable in java How to configure path environment variable in java Nov 15, 2023 pm 01:20 PM

Configuration steps: 1. Find the Java installation directory; 2. Find the system environment variable settings; 3. In the environment variable window, find the variable named "Path" and click the edit button; 4. In the pop-up edit environment variable window , click the "New" button, and enter the Java installation path in the pop-up dialog box; 5. After confirming that the input is correct, click the "OK" button.

How to correctly set the PATH environment variable in Linux How to correctly set the PATH environment variable in Linux Feb 22, 2024 pm 08:57 PM

How to correctly set the PATH environment variable in Linux In the Linux operating system, environment variables are one of the important mechanisms used to store system-level configuration information. Among them, the PATH environment variable is used to specify the directories in which the system searches for executable files. Correctly setting the PATH environment variable is a key step to ensure the normal operation of the system. This article will introduce how to correctly set the PATH environment variable in Linux and provide specific code examples. 1. Check the current PATH environment variable and enter the following command in the terminal

The role and importance of the PATH environment variable in Linux The role and importance of the PATH environment variable in Linux Feb 21, 2024 pm 02:09 PM

"The Role and Importance of the PATH Environment Variable in Linux" The PATH environment variable is one of the very important environment variables in the Linux system. It defines which directories the system searches for executable programs. In the Linux system, when the user enters a command in the terminal, the system will search one by one in the directories listed in the PATH environment variable to see if the executable file of the command exists. If found, it will be executed. Otherwise, "commandnotfound" will be prompted. The role of the PATH environment variable: Simplified

What should I do if my iwatch only lights up with the logo but does not turn on? What should I do if my iwatch only lights up with the logo but does not turn on? Mar 25, 2023 pm 02:00 PM

Reasons and solutions for why iwatch only lights up the logo but does not turn on: 1. It is caused by insufficient power and cannot be turned on. You can put the back of the iwatch on the charger; 2. It is caused by system version problems. You can roll the system back to the stable version; 3. , caused by charger or charging cable failure, you can use another iwatch magnetic charging cable and another USB power adapter; 4. caused by hardware failure, it is recommended to go to a professional third-party testing machine for maintenance.

See all articles