This article mainly for you to share a piece of PHP how to realize the problem of the generation of two-dimensional code through QRCode, has a very good reference value, hope to help you. Follow the small series together to see it.
<?php
/**
* phpqrcode.php provides a key PNG () method, where The
* parameter $text represents the generation of two-bit information text;
* parameter $outfile indicates whether to output a QR code picture file, default no;
* parameter $level indicates fault tolerance, that is, the covered area can also be identified, respectively L (qr_eclevel_l, 7%), M (qr_eclevel_m,15%), Q (qr_eclevel_q,25%), H (qr_eclevel_h,30%);
* Parameter $size indicates the image size is generated, default is 3; Margin indicates the spacing between the border spaces around the QR code, and the
* parameter $saveandprint indicates whether to save the QR code and display it.
* public static function png ($text, $outfile =false, $level =qr_eclevel_l, $size =3, $margin =4, $saveandprint =false) br> {
$enc = qrencode::factory ($level, $size, $margin);
Return $enc->encodepng ($text, $outfile, $saveandprint =false);
}
*
Calling PHP QR code is very simple, and the following code generates a QR code with the content "http://www.baidu.com/".
<p> include ' phpqrcode.php ';
QRCode::p ng (' http://www.baidu.com/'); </p>
*/
include ' phpqrcode/phpqrcode.php ';
Two-dimensional code content
$value = ' iphone ';
Fault tolerance level
$errorCorrenctionLevel = ' l ';
QR code image size
$matrixPointSize = 6;
$path = Runtime_path. " temp/qrcode/";
The generated file name
$fileName = $path. Time (). PNG ';
//generate QR Code
QRCode::p ng ($value, $fileName , $errorCorrenctionLevel, $matrixPointSize, 2);
//Image logo added QR code
$logo = ' 6s.jpg ';
$qrcode = $fileName;//QR code path
$logo = imagecreatefromstring (file_get_contents ($logo));
$qrcode = imagecreatefromstring (file_get_contents ($qrcode));
$QR _width = Imagesx ($qrcode);//QR code picture width
$QR _height = Imagesy ($qrcode);//QR code picture 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 picture and resize
imagecopyresampled ($qrcode, $logo, $from _width, $from _width, 0, 0, $logo _qr_width, $logo _qr_ Height, $logo _width, $logo _height);
//Save the generated QR code
imagepng ($qrcode, ' helloweixin.png ');
Echo ' ';
Related recommendations:
Three ways to generate two-dimensional code in PHP
PHP generates two-dimensional code
PHP Two-dimensional code generation class library to generate two-dimensional code