PHP implementation generated with two-dimensional code image and forced to download the steps in detail

Source: Internet
Author: User
This time for everyone to bring PHP implementation generated with two-dimensional code image and forced to download the steps in detail, PHP implementation of the generation with two-dimensional code images and mandatory download of the attention to what, the following is the actual case, take a look.

/* Download QR code */Public Function test () {//Receive passed parameters $data [' keys '] = [' B01id ' =>trim (I (' get.b01id '), ' B02id ' =>trim ( I (' get.b02id ')), ' B03id ' =>trim (i (' get.b03id ')), ' Brid ' =>trim (i (' Get.brid ')), ' Unicon ' =>trim (i ('  Get.unicon ')];  if (Empty ($data [' Keys '] [' b01id ']) $this->error (' Merchant does not exist ', U (' Seller/index '), 3); $res = D (' Sellerbrcode ')->download ($data);  The method below if (!is_array ($res)) $this->error ($res, U (' Seller/index '), 3); if (!empty ($res [' Error '])) $this->error ($res [' Error '],u (' Seller/seebrcode? ').  $res [' url ']), 3); Make code card $bgimg = imagecreatefromstring (file_get_contents ($res [' bgimg '));  Get the background map to do canvas import (' Component/phpqrcode ', App_path, '. php '); Introduce two-dimensional code generation class//If there is a scan code 1232-D code, then generate a scan code 1232-D code if (' '! = $res [' Codea ']) {/* parameter description: * Parameter 1: QR code needs to keep the value of * parameter 2:false represents the direct output, others are raw   File name * Parameter 3: Error correction level: L, M, Q, H * Parameter 4: Point size, the larger the value of the larger the picture * */\qrcode::p ng ($res [' Codea '], $res [' codeimg '], ' h ', 18); /* Use picture Scaling method bool Imagecopyresized ($DST _im, $src _im, $dst _x, $dst _y,$src _x, $src _y, $dst _w, $dst _h, $src _w, $src _h) dst_im target image linked resources.     A resource that src_im the source image link.     Dst_x The x-coordinate of the destination.     Dst_y y-coordinate destination.     Src_x the source point of the x-coordinate.     Src_y the y-coordinate source point.     Dst_w the destination width.     Dst_h target height.     Src_w the source width.    Src_h source height. * */$codeimg = imagecreatefromstring (file_get_contents ($res [' codeimg ')]);        Get the QR code picture $BG _info = getimagesize ($res [' codeimg ']);  Get the size of the original two-dimensional code picture imagecopyresized ($bgimg, $codeimg, 1520,550,0,70,700,666, $BG _info[0], $bg _info[1]-36);   }//If there is a UnionPay cloud Flash payment QR code, then generate UnionPay cloud flash QR code picture if (' '! = $res [' codeb ']) {\qrcode::p ng ($res [' Codeb '], $res [' paycodeimg '], ' H ', 18); $codeimg = imagecreatefromstring (file_get_contents ($res [' paycodeimg '));//get QR code picture $BG _info = getimagesize ($res ['       Paycodeimg ']);  Get the size of the original two-dimensional code picture imagecopyresized ($bgimg, $codeimg, 236,536,0,80,750,670, $BG _info[0], $bg _info[1]-80);   }//If there is a merchant promotion QR code, then generate merchant promotion QR code picture if (' '! = $res [' codec ']) {\qrcode::p ng ($res [' codec '], $res [' bridimg '], ' H ', 18); $codeimg = imagecreatefromstring (file_get_contents ($res [' BridIMG ']));        Get the QR code picture $BG _info = getimagesize ($res [' bridimg ']);  Get the size of the original two-dimensional code picture imagecopyresized ($bgimg, $codeimg, 1375,1288,0,0,230,230, $BG _info[0], $BG _info[1]);     }//If there is a merchant name if (' '! = $res [' bname ']) {//In order to center the text, you need to calculate the left offset preg_match_all ("/[0-9]{1}/", $res [' bname '], $len 1);    Get the number of words in the string Preg_match_all ("/[a-za-z]{1}/", $res [' bname '], $len 2); Get the number of letters in the string Preg_match_all ("/([\x{4e00}-\x{9fa5}]) {1}/u", $res [' bname '], $len 3);   Get the number of Chinese in the string $left = 610-(COUNT ($len 1[0]) * (COUNT ($len 2[0]) * (COUNT ($len 3[0]) * 28); $res [' filename ']. = ' _ '.       $res [' bname '];    Append two-D code name $black = Imagecolorallocate ($bgimg, 0x20, 0x57, 0xa0);  Font Color imagefttext ($bgimg, 0, $left, 480, $black, './public/font/msyh.ttf ', $res [' bname ']);    }//If there is a QR code number, write a QR code number if (' '! = $res [' Brid ']) {$black = Imagecolorallocate ($bgimg, 0x3e, 0x75, 0xc7);  Font Color imagefttext ($bgimg, 0, 1720,1190, $black, './public/font/msyh.ttf ', $res [' Brid ']); }//Add UnionPay cloud Flash logo $codeimg = Imagecreatefromstring (file_get_contents ($res [' Union ')]);         Get the QR code picture $BG _info = getimagesize ($res [' Union ']); Get the original logo image size imagecopyresized ($bgimg, $codeimg, 550,760,0,0,120,120* $bg _info[1]/$bg _info[0], $BG _info[0], $BG _  INFO[1]);  Add code 123logo $codeimg = imagecreatefromstring (file_get_contents ($res [' logo ')]);         Get the QR code image $BG _info = getimagesize ($res [' logo ']); Get the original logo image size imagecopyresized ($bgimg, $codeimg, 1805,770,0,0,120,120* $bg _info[1]/$bg _info[0], $BG _info[0], $BG _  INFO[1]); $res [' filename ']. = ' _ '. Date (' y-m-d ', Time ()).    '. png '; Append two-D code name header (' Pragma:public ');  Required header (' expires:0 ');  No cache header (' Cache-control:must-revalidate, post-check=0, pre-check=0 ');  Header (' Cache-control:private ', false);  Header (' content-type:application/force-download ');  Header (' content-disposition:attachment; filename= '. $res [' filename ']. ' "');  Header (' content-transfer-encoding:binary ');  Header (' Connection:close '); Imagepng ($BGIMG); }/* before creating a picture Splicing data */public function Download ($data) {$tool = D (' tool '),//Get public class $mysql = M (), $admin = I (' session.admin ');/* stitching URL, convenient for the following error , the jump uses */$show [' url '] = ' b01id= '. $data [' Keys '] [' b01id '];//if the user ID is passed, determine if the user belongs to the merchant if ($data [' Keys '] [' b03id ']) $show [' url '].= ' &b03id= '. $data [' Keys '] [' b03id '];//if a QR code is passed idif ($data [' Keys '] [' b02id ']) $show [' url '].= ' &b02id= '. $data [' Keys '] [' b02id '];//if the UnionPay cloud Flash payment if ($data [' Keys '] [' Unicon ']) $show [' url '].= ' &unicon= '. $data [' Keys '] [' Unicon '];//if the promo QR code is passed if ($data [' Keys '] [' Brid ']) $show [' url '].= ' &brid= '. $data [' Keys '] [' Brid '];//call the upper method to get the data $ data = $this->seebrcode ($data, $tool, $mysql, $admin, False), if (!is_array ($data)) {return [' error ' + = $data, ' url ' = > $show [' url ']; }/* get the data to show */$show [' bgimg ']= './public/img/qrcode/qrcode.png ';//Background Image address $show[' logo ']= './public/img/qrcode/ Logo.png ';//code 123 logo address $show[' union ' = './public/img/qrcode/unionpay.png ';//UnionPay logo address $show[' codeimg ']= './public /img/qrcode/code.png ';//common QR code generated save address $show[' paycodeimg '] = './public/img/Qrcode/paycode.png ';//UnionPay Two-dimensional code generated by the Save address $show[' bridimg ']= './public/img/qrcode/brid.png ';//merchant promotion QR code image save Address $show[' FileName ']= ' scan code 123 receive two-dimensional code ';//QR code name//scan code 1232-dimensional code content $show[' Codea ']= (! $data [' Keys '] [' b02id '])? ": Isset ($data [' QRCode '] [$data [' Keys '] [' b02id ']])? $data [' Url1 ']. $data [' QRCode '] [$data [' Keys '] [' b02id ']][' Brcode ']: ';//sweep code 1232-dimensional code number $show[' Brid ']= (! $data [' Keys '] [' B02id '])? ": Isset ($data [' QRCode '] [$data [' Keys '] [' b02id ']])? ' NO. '. $data [' Keys '] [' b02id ']: ';//UnionPay QR code $show[' codeb ']= (! $data [' Keys '] [' Unicon '])? ": Isset ($data [' QRCode '] [$data [' Keys '] [' Unicon ']])? $data [' QRCode '] [$data [' Keys '] [' Unicon ']][' Brcode ']: ';//merchant promotion QR code $show[' codec ']= (! $data [' Keys '] [' Brid '])? ": Isset ($data [' Download '] [$data [' Keys '] [' Brid ']])? $data [' Url2 ']. $data [' Download '] [$data [' Keys '] [' Brid ']][' Brcode ']: ';//Merchant name $show[' bname ']= empty ($data [' seller '] [' Bshortname ']) ? (Empty ($data [' seller '] [' bname '])? (Empty ($data [' seller '] [' bcode '])? $data [' Seller '] [' b01id ']: $data [' seller '] [' Bcode ']): $data [' Seller ' [' bname ']): $data [' seller '] [' bshortname '];/* if there is an old picture, delete the old picture */if (Is_file ($res [' codeimg ']) unlink ($res [' Codeimg ']);//delete the old sweep code 1232-D code picture if (Is_file ($res [' paycodeimg ')) unlink ($res [' paycodeimg ']); Delete old UnionPay cloud flash QR code image if (Is_file ($res [' paycodeimg '])) unlink ($res [' paycodeimg ']); Delete the old merchant promotion QR code picture return $show;}

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

In_array implicit conversion implementation steps in PHP

PHP Record search engine crawling process of the detailed method

Related Article

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.