Home >Backend Development >PHP Tutorial >How to generate QR code in php through Qrcode
This article mainly shares with you an article on how to generate QR codes in PHP through Qrcode. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to have a look.
/** include 'phpqrcode.php';
* phpqrcode.php provides a key png() method, where
* The parameter $text represents the generated two-digit information text;
* The parameter $outfile represents whether to output a QR code image file. The default is no;
* Parameter $level represents the fault tolerance rate, that is, the covered area can still be identified, which are L (QR_ECLEVEL_L, 7%), M (QR_ECLEVEL_M, 15%), Q (QR_ECLEVEL_Q, 25%) , H (QR_ECLEVEL_H, 30%);
* Parameter $size indicates the size of the generated image, the default is 3; Parameter $margin indicates the spacing value of the blank area of the border around the QR code;
* Parameter $saveandprint indicates whether to save the second QR code and display.
* public static function png($text, $outfile=false, $level=QR_ECLEVEL_L, $size=3, $margin=4, $saveandprint=false)
{
$enc = QRecode:: factory($level, $size, $margin);
return $enc->encodePNG($text, $outfile, $saveandprint=false);
}
*
Call PHP QR Code is very simple. The following code can generate a QR code with the content "http://www.baidu.com/".
QRcode::png('http://www.baidu.com/');
*/
include 'phpqrcode/phpqrcode.php';
// QR code content
$value = 'iphone';
//Error tolerance level
$errorCorrenctionLevel = 'l';
//QR code image size
$matrixPointSize = 6;
$path = RUNTIME_PATH."Temp/qrcode/";
// Generate File name
$fileName = $path.time().'.png';
//Generate QR code
Qrcode::png( $value,$fileName,$errorCorrenctionLevel,$matrixPointSize,2);
//Add QR code to picture logo
$logo = '6s.jpg';
$qrcode = $fileName ;//QR code path
$logo = imagecreatefromstring(file_get_contents($logo));
$qrcode = imagecreatefromstring(file_get_contents($qrcode));
$QR_width = imagesx($qrcode) ;//Width of QR code image
$QR_height = imagesy($qrcode);//Height of QR code image
$logo_width = imagesx($logo);//Width of logo image
$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;
//Recombine the image and resize it
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 QR code in php
PHP QR code generation class library generates QR code
The above is the detailed content of How to generate QR code in php through Qrcode. For more information, please follow other related articles on the PHP Chinese website!