Under PHP create two dimensional code with website LOGO in the middle through QRCode class library

  • 2021-07-07 06:40:56
  • OfStack

We need to generate 2-D code with the help of a number of class libraries to achieve, the following I introduce the use of PHP QR Code to generate 2-D code bar, the generation method is very simple, I will introduce 1 below.

It is realized by using php class library PHP QR Code. There is no need to install additional php extension. First, download the class library package, and sometimes the address cannot be opened. The address is http://phpqrcode.sourceforge.net/

Download:
Domestic download: https://www.ofstack.com/codes/189897. html
Foreign download: http://sourceforge.net/projects/phpqrcode/

For example, use the PHP QR Code class library to create 2-D code.

1. Browser output:


<? 
include "phpqrcode/phpqrcode.php"; 
$value="https://www.ofstack.com"; 
$errorCorrectionLevel = "L"; 
$matrixPointSize = "4"; 
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize); 
exit; 
?>

2. File output 2D code


include('phpqrcode/phpqrcode.php'); 
// 2 Dimension code data  
$data = 'https://www.ofstack.com'; 
//  Generated file name  
$filename = '1111.png'; 
//  Error correction level: L , M , Q , H 
$errorCorrectionLevel = 'L'; 
//  Size of dot: 1 To 10 
$matrixPointSize = 4; 
QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);

3. Generate 2-D code with logo in the middle


<?php 
include('phpqrcode/phpqrcode.php'); 
$value='https://www.ofstack.com'; 
$errorCorrectionLevel = 'L'; 
$matrixPointSize = 6; 
QRcode::png($value, 'xiangyang.png', $errorCorrectionLevel, $matrixPointSize, 2); 
echo "QR code generated"."<br />"; 
$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'); 
?>

Related articles: