


Summary of how to generate QR code with logo in php, summary of phplogo_PHP tutorial
A summary of how php generates a QR code with a logo, a summary of phplogo
1. Class libraries used
1. phpqrcode (php library)
2. qrcode.js (javascript library)
2. Use of phpqrcode
Only uses the PHP class library, that is, the generation of QR codes is operated in the background. Because you want to generate a QR code with a logo in the background, you must first upload the logo image to the server (I used webuploader for uploading)
How to use phpqrcode:
First download phpqrcode: http://phpqrcode.sourceforge.net/
Then remember to introduce the phpqrcode.php file before using it
$value = $url;//二维码内容 $errorCorrectionLevel = 'L';//设置容错级别 $matrixPointSize = $size;//生成图片大小 QRcode::png($value, 'public_files'.DIRECTORY_SEPARATOR .'code'.DIRECTORY_SEPARATOR .'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);//生成二维码图片 无logo $logo = $tar_path;//上传至服务器的logo图片 $QR = 'public_files'.DIRECTORY_SEPARATOR .'code'.DIRECTORY_SEPARATOR .'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); } $name = time(); imagepng($QR, 'public_files'.DIRECTORY_SEPARATOR .'code'.DIRECTORY_SEPARATOR .$name.'.png');//输出带logo的二维码图片
3. Use of qrcode.js
Use qrcode.js to directly generate QR codes on the front end. You first need to download jquery.qrcode.js
The use of qrcode is also very simple:
var length = size*80;//设置二维码大小 length = parseInt(length); $("#code_img").qrcode({ //code_img是一个img标签的id render : "canvas", //设置渲染方式,有table和canvas,使用canvas方式渲染性能相对来说比较好 text : url, //扫描二维码后显示的内容,可以直接填一个网址,扫描二维码后自动跳向该链接 width : length, //二维码的宽度 height : length, background : "#ffffff", //二维码的后景色 foreground : "#000000", //二维码的前景色 src: $('#image').attr('src') //二维码中间的图片 });
After introducing jquery.qrcode.js, write this js code yourself. After execution, the QR code can be displayed and processed
Mainly the logo reference format in the middle of the QR code. Generally, there are two formats for taking local images: one is the local URL, and the other is to convert the image into base64 format
At first I tried the local URL format to reference images, but found that I could only reference images in the same directory as the js file, so the local URL format was not supported, so I adopted the latter method.
Use
To upload and select a local image, and then take its base64 format
var input = document.getElementById("file_input"); if(typeof FileReader==='undefined'){ input.setAttribute('disabled','disabled'); }else{ input.addEventListener('change',readFile,false); } function readFile(){ var file = this.files[0]; if(!/image\/\w+/.test(file.type)){ alert("文件必须为图片!"); return false; } var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function(e){ $('#image').attr('src',this.result);//image为img标签的id } }
Read the file as a string of Data URL strings, and read the small file directly into the page with a URL address in a special format. This special format is base64
3. Comparison between the two class libraries
Two class libraries, one operates in the background and the other operates directly in the front end.
phpqrcode generates QR codes and operates in the background, and the generated images are saved on the server. Generally, the generated QR code is saved directly to the local and then used directly. It is rare to go to the server to obtain it for a second time. Therefore, using phpqrcode will cause the images in the server to accumulate, occupying unnecessary space, and deleting them will also cost extra money. overhead. So using phpqrcode is not suitable for this QR code generation tool. Moreover, uploading images will also incur extra overhead
qrcode.js operates directly on the front-end, uploads images and saves them directly in the browser, and generates QR codes directly on the front-end without any background interference. This reduces unnecessary overhead and does not cause image corruption on the server. Stack up and take up unnecessary space.
Articles you may be interested in:
- Several ways to generate QR codes with php and their use examples
- How to create your own QR code for images with php in the middle
- Two ways to use PHP to generate QR codes (with logo images)
- Create QR codes with website LOGO in the middle through the QRCode class library under PHP
- Generate with php Solutions to Chinese garbled characters when QR codes appear
- Generate business cards, links and other QR codes based on JavaScript
- Summary of JavaScript-generated QR code pictures

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment