search
HomePHP LibrariesOther librariesphpqrcode-master QR code generation class
phpqrcode-master QR code generation class

Calling PHP qrCode is very simple. The following code can generate a QR code with the content "http://www.php.cn".

Php code

include ' phpqrcode.php';

QRcode::png('"http://www.php.cn');

Then in actual application, we will add in the middle of the QR code Adding your own LOGO has enhanced the publicity effect. So how to generate a QR code containing the logo? In fact, the principle is very simple. First use PHP qr Code to generate a QR code image, and then use PHP's image related functions to prepare the QR code in advance. The logo image is added to the middle of the original QR code image just generated, and then a new QR code image is regenerated.

<?php 
include 'phpqrcode.php'; 
$value = 'http://www.learnphp.cn'; //二维码内容 
$errorCorrectionLevel = 'L';//容错级别 
$matrixPointSize = 6;//生成图片大小 
//生成二维码图片 
QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2); 
$logo = 'logo.png';//准备好的logo图片 
$QR = 'qrcode.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图片宽度 
$logo_height = imagesy($logo);//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, 'helloweba.png'); 
echo '<img src="helloweba.png">'; 
?>


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

phpqrcode class generates QR code methodphpqrcode class generates QR code method

16Mar2018

It is quite difficult to generate QR codes using PHP language, except of course for calling the interface that generates QR code images. If you write the code to generate it yourself, you really have no way to start. However, we can use phpqrcode, a ready-made class file and PHP QR code generation class library, to easily generate QR codes.

phpqrcode class library generates QR code example codephpqrcode class library generates QR code example code

03Mar2018

This article mainly shares with you the phpqrcode class library to generate QR code example code, hoping to help everyone.

Generate QR code using PHP class library PHPqrCodeGenerate QR code using PHP class library PHPqrCode

07Jul2018

This article mainly introduces the use of PHP class library PHPqrCode to generate QR codes. It has certain reference value. Now I share it with you. Friends in need can refer to it.

WeChat development QR code generation classWeChat development QR code generation class

11Mar2017

This article mainly introduces the QR code generation class for PHP WeChat development. This article uses the WeChat interface to realize the generation of QR codes and directly gives sample codes. Friends who need it can refer to it.

Detailed explanation of phpqrcode class to generate QR codeDetailed explanation of phpqrcode class to generate QR code

24Mar2018

This time I will bring you a detailed explanation of how to generate a QR code with the phpqrcode class. What are the precautions for generating a QR code with the phpqrcode class? Here is a practical case, let’s take a look.

PHP QR Code barcode and QR code generation class libraryPHP QR Code barcode and QR code generation class library

25Jul2016

PHP QR Code barcode and QR code generation class library

See all articles