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

How Do I Link Static Libraries That Depend on Other Static Libraries?How Do I Link Static Libraries That Depend on Other Static Libraries?

13Dec2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

How to Silence TensorFlow\'s Debugging Output?How to Silence TensorFlow\'s Debugging Output?

28Oct2024

Suppression of Tensorflow Debugging OutputTensorflow prints extensive information about loaded libraries, found devices, and other debugging data...

How Does jQuery Simplify DOM Manipulation for Web Developers?How Does jQuery Simplify DOM Manipulation for Web Developers?

03Jan2025

Overflow: Hidden and Expansion of HeightjQuery distinguishes itself from other JavaScript libraries through its cross-platform compatibility and...

Which native Java image processing library is right for you?Which native Java image processing library is right for you?

30Oct2024

Native Java Image Processing Libraries for High-Quality ResultsAs you have encountered limitations with ImageMagick and JAI, let's explore other...

How to Execute Command Line Binaries in Node.js?How to Execute Command Line Binaries in Node.js?

27Dec2024

Executing Command Line Binaries in Node.jsExecuting third-party binaries is an essential task when porting CLI libraries from other languages to...

How to Create and Utilize Static Libraries in g  ?How to Create and Utilize Static Libraries in g ?

24Oct2024

This article guides developers on crafting static libraries in C using g . It demonstrates how to compile source code into object files, create static libraries, and incorporate them into other projects. By leveraging this approach, developers can

See all articles