Yii integration Phpqrcode generate two-dimensional code with online demo address, Yiiphpqrcode
1, first to the official website download package http://phpqrcode.sourceforge.net/
After downloading the class library provided by the official website, we only need to use phpqrcode.php to generate the QR code, of course, your PHP environment must turn on support GD2.
Phpqrcode.php provides a key PNG () method, where
The parameter $text represents the generated two-bit information text;
The parameter $outfile indicates whether the output QR code picture file, default no;
The parameter $level represents the fault tolerance, i.e., the area covered is also recognized, respectively L (qr_eclevel_l,7%), M (qr_eclevel_m,15%), Q (qr_eclevel_q,25%), H (qr_eclevel_h,30%) ;
The parameter $size indicates the generated picture size, the default is 3, and the parameter $margin indicates the spacing value of the border space around the two-dimensional code;
The parameter $saveandprint indicates whether to save the QR code and display it.
2, after downloading the extracted Phpqrcode folder into the Extensions folder, such as:
3, introduce class Phpqrcode
Yii:: $enableIncludePath = false; Yii::import (' Application.extensions.phpqrcode.phpqrcode ', 1);
Here is the complete method of generating the QR code
Public Function Actionqrcode () {$this->breadcrumbs=array_merge ($this->breadcrumbs,array (' Generate two-dimensional code ')); $qrcode _ Path= '; $file _tmp_name= '; $errors =array (); if (!empty ($_post)) {$content = Trim ($_post[' content ']);//Two-D code contents $ Contentsize= $this->getstringlength ($content), if ($contentSize >290) {$errors []= ' word is too long, no more than 150 characters! ';} Yii:: $enableIncludePath = false; Yii::import (' Application.extensions.phpqrcode.phpqrcode ', 1), if (Isset ($_files[' upimage ' [' tmp_name ']) && $_files[' upimage ' [' tmp_name '] && is_uploaded_file ($_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 you uploaded is not in the correct format and only supports PNG, JPG, GIF format. ";}} $tpgs =$_post[' tpgs '];//picture format $bas_path=dirname (Yii::app ()->basepath); $qrcode _bas_path= $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{//solve the problem of garbled Chinese file names under Windows $save_path = helper::safeencoding ($qrcode _path, ' GB2312 '); {$errors [_path ') 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//generate QR code picture qrcode::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 (file_exists ($logo)) {$QR = Imagecreatefromstring (file_get_contents ($QR)); $logo = Imagecreatefromstring (file_get_contents ($logo)); $QR _width = Imagesx ($QR);//two-dimensionalCode image Width $qr_height = imagesy ($QR);//QR code image Height $logo_width = imagesx ($logo);//logo picture Width $logo_height = Imagesy ($logo);// Logo image 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 picture and resize imagecopyresampled ($QR, $logo, $from _width, $from _width, 0, 0, $log O_qr_width, $logo _qr_height, $logo _width, $logo _height);//Output picture//Header ("Content-type:image/png"); Imagepng ($QR, $ Qrcode_path); Imagedestroy ($QR);} else{$qrcode _path= $qrcode _path_new;} $qrcode _path=str_replace ($bas _path, ", $qrcode _path);} else{$qrcode _path= ';}} $data =array (' Data ' =>array (' errors ' = $errors, ' qrcode_path ' + $qrcode _path)]; $this->render (' QRCode ', $ data);}
Front-page Upload interface:
request->hostinfo; $matrixPointSize =6; $matrixMarginSize =2; $errorCorrectionLevel = ' M '; $tpgs = ' gif '; if (!empty ($_ POST) {$content =$_post[' content ']; $matrixPointSize =$_post[' matrixpointsize '); $matrixMarginSize =$_post[' Matrixmarginsize ']; $errorCorrectionLevel =$_post[' errorcorrectionlevel '); $tpgs =$_post[' Tpgs '];} $arrayCorrectionLevel =array (' L ' + = ' l-low (7) ', ' M ' = = ' M-medium (15%) ', ' Q ' = ' q-quartile ' (25%) ', ' H ' = = ' h-h IgH (30%) '); $arrayTpgs =array (' gif ' + ' gif format ', ' png ' = ' png ' format ', ' jpg format ');? >Generate two-dimensional code online
Beginwidget (' Cactiveform ', array (' id ' = ' qrcode-form ', ' htmloptions ' = = Array (' id ' = ' view_table ', ' class ' =& Gt ' Add-form padding-10 ', ' enctype ' = ' multipart/form-data '), ' enableajaxvalidation ' = false);? >Size Size
>
Margin Size
>
Fault tolerance level
' Form-control '); >Save Format
' Form-control '); >Two-dimensional code content
' Form-control ', ' maxlength ' =>150);? >Two-dimensional code logo imageSelect File
Endwidget ();?>Two-dimensional code
Build Failed
"target=" > "_blank"Right-click to save as two-dimensional code
RenderPartial ('/component/duoshuo_common ');? >
Demo Address
http://www.bkjia.com/PHPjc/1070041.html www.bkjia.com true http://www.bkjia.com/PHPjc/1070041.html techarticle Yii Integration Phpqrcode generated two-dimensional code with the online demo address, Yiiphpqrcode 1, first to the official website download package http://phpqrcode.sourceforge.net/Download the library provided by the website, only need to use p ...