Home > Backend Development > PHP Tutorial > PHP combined with phpqrcode generates QR code with picture LOGO

PHP combined with phpqrcode generates QR code with picture LOGO

WBOY
Release: 2016-08-08 09:21:49
Original
1003 people have browsed it

PHP generates QR codes with LOGO. Maybe many experts have already achieved it, but they didn’t pay too much attention to this aspect before. There is a small project in this section that requires QR code generation, so I checked some information and sent it. There is a PHP class library phpqrcode that is very convenient for generating this kind of QR code. I tested it on the index. I will share my usage and code with novices. I hope experts can encourage me.

Generation effect: Logo picture in the middle

First you need to download this class library package, or I will attach this class library later, the specific usage code:

1. Basic QR code generation unit, Directly output standard QR code:

<?php    
//文件输出    
    include(&#39;phpqrcode.php&#39;);    
// 二维码数据    
    $data = &#39;http://www.codesc.net&#39;;    
// 生成的文件名    
   $filename = &#39;ewm.png&#39;;   
// 纠错级别:L、M、Q、H    
    $errorCorrectionLevel = &#39;L&#39;;    
// 点的大小:1到10    
    $matrixPointSize = 4;    
    QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);    
?> 
Copy after login

2. Generate standard QR code and QR code with logo:

<?php
include (&#39;phpqrcode.php&#39;);
$value = &#39;http://www.codesc.net&#39;;//二维码数据
$errorCorrectionLevel = &#39;L&#39;;//纠错级别:L、M、Q、H
$matrixPointSize = 10;//二维码点的大小:1到10
QRcode::png ( $value, &#39;ewm.png&#39;, $errorCorrectionLevel, $matrixPointSize, 2 );//生成不带Logo的二维码图片文件名
echo "二维码已生成" . "<br />";
$logo = 'emwlogo.gif';//需要显示在二维码中的Logo图像
$QR = 'ewmlogo.png';//生成带Logo的二维码文件名
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, 'ewmlogo.png' );
?>
Copy after login

Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

The above introduces the use of php combined with phpqrcode to generate a QR code with a picture LOGO, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template