ThinkPHP3.2.3 extended QR code, thinkphp3.2.3 extension _php tutorial

Source: Internet
Author: User

ThinkPHP3.2.3 extended QR code, thinkphp3.2.3 extension


First, the path is set.

Simple to use no Logo:

Public Function QRCode () {        Vendor (' Phpqrcode.phpqrcode ');        Generate QR code image        $object = new \qrcode ();        $url = ' http://www.shouce.ren/';//URL or text content        $level =3;        $size =4;        $errorCorrectionLevel =intval ($level);//Fault tolerance level        $matrixPointSize = Intval ($size);//Generate picture size        $object->png ($ URL, False, $errorCorrectionLevel, $matrixPointSize, 2);    }

Advanced use with Logo:

Public Function QRCode () {Vendor (' phpqrcode.phpqrcode ');        Generate QR code image $object = new \qrcode ();        $qrcode _path= ';        $file _tmp_name= ';        $errors =array (); if (!empty ($_post)) {$content = Trim ($_post[' content ');//two-D code content $contentSize = $this->getstringleng            Th ($content); if ($contentSize >150) {$errors []= ' word is too long and cannot be more than 150 characters!            '; } if (Isset ($_files[' upimage ' [' tmp_name ']) && $_files[' upimage ' [' tmp_name '] && is_uploaded_fil E ($_files[' upimage ' [' tmp_name '])) {if ($_files[' upimage ' [' Size ']>512000) {$errors []= "The file you uploaded is too large to exceed 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 []=] The file format you uploaded is incorrect and only supports PNG, JPG, GIF format. ";               }} $tpgs =$_post[' Tpgs '];//picture format $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;//The original picture path $qrcode _path_new= $qrcode _bas_path. $uniqid _rand. " _2. ". $tpgs;//QR Code picture Path if (helper::getos () = = ' Linux ') {$mv = Move_uploaded_file ($file _tmp_name, $qrcode _p            ATH);                }else{//Solve the problem of Chinese file name garbled in Windows $save _path = helper::safeencoding ($qrcode _path, ' GB2312 '); if (! $save _path) {$errors []= ' upload failed, please try again!                ';            } $MV = Move_uploaded_file ($file _tmp_name, $qrcode _path);                } if (empty ($errors)) {$errorCorrectionLevel = $_post[' errorcorrectionlevel '];//fault tolerance level $matrixPointSize = $_post[' matrixpointsize '];//generate picture size $matrixMarginSize = $_post[' matrixmarginsize '];//margin size//build                QR code image $object::p ng ($content, $qrcode _path_new, $errorCorrectionLevel, $matrixPointSize, $matrixMarginSize); $QR = $qrcode _path_new;//has generated the original two-dimensional code graph $logo = $qrcode _path;//Ready logo image if (fi                    Le_exists ($logo)) {$QR = Imagecreatefromstring (file_get_contents ($QR));                    $logo = imagecreatefromstring (file_get_contents ($logo));  $QR _width = Imagesx ($QR);//QR code image width $QR _height = Imagesy ($QR);//QR code image height $logo _width =  Imagesx ($logo);//logo picture width $logo _height = Imagesy ($logo);//logo picture height $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;             Regroup and resize the picture imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $logo _qr_widt                    H, $logo _qr_height, $logo _width, $logo _height);                    Output Image//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 ();

Demo Address: Http://www.shouce.ren/tool/qrcode

Helper classes for helpers address: http://www.thinkphp.cn/topic/34875.html

  

http://www.bkjia.com/PHPjc/1093104.html www.bkjia.com true http://www.bkjia.com/PHPjc/1093104.html techarticle ThinkPHP3.2.3 Extension of the two-dimensional code, thinkphp3.2.3 extension of the first photo path. Simple to use without Logo:public function QRCode () {Vendor (' phpqrcode.phpqrcode ');//generate QR code ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.