This article mainly introduces how to use the QRCode class library in php to create a QR code with a LOGO in the middle, and the example code of QRcode to generate a QR code, if you want to generate a QR Code, you need to use some class libraries to generate the QR Code. The following describes how to generate a QR Code using php qr Code. the method is simple, next I will introduce it.
Using php class library php qr Code to achieve, do not need to install additional php extensions, first download the class library package, sometimes the address cannot open, address: http://phpqrcode.sourceforge.net/
Download:
Domestic Download: http://www.bitsCN.com/codes/189897.html
Foreign Download: http://sourceforge.net/projects/phpqrcode/
Example: Use the php qr Code class library to create a QR Code.
1. browser output:
<? include "phpqrcode/phpqrcode.php"; $value="http://www.bitsCN.com"; $errorCorrectionLevel = "L"; $matrixPointSize = "4"; QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize); exit; ?>
2. file output QR code
Include ('phpqrcode/phpqrcode. php '); // QR code data $ data = 'http: // www.jbxue.com'; // generated file name $ filename = '1111.png '; // error correction level: l, M, Q, H $ errorCorrectionLevel = 'l'; // the point size: 1 to 10 $ matrixPointSize = 4; QRcode: png ($ data, $ filename, $ errorCorrectionLevel, $ matrixPointSize, 2 );
3. generate a QR code with a central logo
<?php include('phpqrcode/phpqrcode.php'); $value='http://www.bitsCN.com'; $errorCorrectionLevel = 'L'; $matrixPointSize = 6; QRcode::png($value, 'xiangyang.png', $errorCorrectionLevel, $matrixPointSize, 2); echo "QR code generated"."
"; $logo = 'logo.png'; $QR = 'xiangyang.png';if($logo !== FALSE) {$QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $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; imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); } imagepng($QR,'xiangyanglog.png'); ?>