


Personalize your own QR code, personalize your own QR code_PHP tutorial
Personalize your own QR code, personalize your own QR code
1. What is a QR code
2. How do we make QR code
3. How to make your own personalized QR code
1. The first step. Download the Php class library phpqrcode, (with download address: http://sourceforge.net/projects/phpqrcode/)
The use cases given online are:
<?php /* $errorCorrectionLevel 纠错级别:L、M、Q、H $matrixPointSize表示图片每个黑点的像素 点的大小:1到10 */ include '/phpqrcode/phpqrcode.php';//引入PHP QR库文件 $value="个性化自己的二维码"; // 二维码数据 $errorCorrectionLevel = "l"; // 纠错级别:L、M、Q、H $matrixPointSize = "10"; // 点的大小:1到10 QRcode::png($value, false, $errorCorrectionLevel); exit; ?>
2. Understand the above code
What wonderful journey happened in the above code?
Let us open phpqrcode.php and take a look. The code is too long, so I won’t post it. You can download it yourself.
Combine the above code with phpqrcode.php and take a look:
<?php /* $errorCorrectionLevel 纠错级别:L、M、Q、H $matrixPointSize表示图片每个黑点的像素 点的大小:1到10 */ include 'phpqrcode/phpqrcode.php'; //引入PHP QR库文件 $intext="个性化自己的二维码"; // 二维码数据 $errorCorrectionLevel = "l"; // 纠错级别:L、M、Q、H $matrixPointSize = "2"; // 点的大小:1到10 $margin = 1; $size = 10; $outfile = false; $saveandprint=false; $enc = QRencode::factory($errorCorrectionLevel, $size, $margin); //$enc->encodePNG($value, false, $saveandprint=false); try { ob_start(); $tab = $enc->encode($intext); print_r($tab); $err = ob_get_contents(); ob_end_clean(); if ($err != '') QRtools::log($outfile, $err); /*标记*/ $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$enc->margin)); QRimage::png($tab, $outfile, min(max(1, $enc->size), $maxSize), $enc->margin,$saveandprint); } catch (Exception $e) { QRtools::log($outfile, $e->getMessage()); } exit; ?>
We can find that the php class library phpqrcode first converts the text we need into the array $tab through an algorithm, and then draws a picture through image manipulation, which is our QR code.
If you print the array $tab, you will find that it looks like this:
Array ( [0] => 1111111010101001001111111 [1] => 1000001001111001001000001 [2] => 1011101011100001101011101 [3] => 1011101011101110101011101 [4] => 1011101010011010001011101 [5] => 1000001000110111001000001 [6] => 1111111010101010101111111 [7] => 0000000000101111100000000 [8] => 1111001010110000110011101 [9] => 1010100010101110100111100 [10] => 1011011111111111111000111 [11] => 0010010011100000100001000 [12] => 0101111111101001100101100 [13] => 0100010111010111010001001 [14] => 0110101010110111010100001 [15] => 1001110110101100110111101 [16] => 0000101100110100111110000 [17] => 0000000011110101100010101 [18] => 1111111001010110101011010 [19] => 1000001001101100100010101 [20] => 1011101001100001111110001 [21] => 1011101010010110000000011 [22] => 1011101011000111011001110 [23] => 1000001011001010001001000 [24] => 1111111011000100100101111 )
Okay, do you understand...
Now it’s simple, just draw based on the array $tab:
QRimage::png($tab, $outfile, min(max(1, $enc->size), $maxSize), $enc->margin,$saveandprint);
3. How to draw
If we all study the source code, we will find that the most critical method is this:
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4);
The source code I commented is posted below (the original class library has no comments)
<?php function image($frame, $pixelPerPoint = 4, $outerFrame = 4){ //$frame就是数组$tab,$pixelPerPoint,$outerFrame现在看不出来是什么,待会解释 $h = count($frame); $w = strlen($frame[0]); //计算应该画多长多宽的画,$h表示高,$w表示宽 $imgW = $w + 2*$outerFrame; $imgH = $h + 2*$outerFrame; //它把画布变大了一点!说明$outerFrame是周围留白大小 $base_image =ImageCreate($imgW, $imgH); //imagecreate — 新建一个基于调色板的图像,换句话说,我们现在可以基于$base_image画画了 $col[0] = ImageColorAllocate($base_image,255,255,255); $col[1] = ImageColorAllocate($base_image,0,0,0); //imagecolorallocate — 为一幅图像分配颜色 //第一个参数是建立的,后面三个分别是R,G,B(大小都是从0到255),你可以理解为颜料……,三个颜料不同比例混合产生了不同的颜色,所以$col[0]就是白色的画笔啦,$col[1]是黑色的画笔(为什么三个255是白色,三个0是黑色,你可以想象一下中学物理里面白光可以分解的实验……) imagefill($base_image, 0, 0, $col[0]); //imagefill — 区域填充 ,整个画布上面都是白色的啊 for($y=0; $y<$h; $y++) { for($x=0; $x<$w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel ($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); } } } //通过两个循环,将$tab数组中的1填充为黑色,剩下的0为白 //$outerFrame表示留白 $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); //ImageCreate这个函数刚刚介绍过了,干嘛又调用…………而且大小是原来的$pixelPerPoint倍! //好吧,$pixelPerPoint是放大倍数,这里开始将刚刚生成的画按需放大(现在只是生成放大的画布) ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); //imagecopyresized — 拷贝部分图像并调整大小 //将刚刚的画放大$pixelPerPoint倍之后复制到新建的画布里面 ImageDestroy($base_image); //imagedestroy — 销毁一图像 return $target_image; //返回生成的最后图像! }
4. What is yours is what is practical.
So…………
(1) Can "black dots" be turned into colored dots? Become love? , turns into a photo of your girlfriend? Become text?
(2) Can you add something in the middle of the image, a word "love", or something that can express your heart?
5. Write your own method
private static function myImage($frame, $pixelPerPoint = 4, $outerFrame = 4, $point, $centerPoint ){ /* * array $point 表示所填充的点的样式 * array $centerPoint 表示图片中间部分的样式 * $point = array ( 'kind'=>'',//col,img,word 'info'=>'' //rgb,filename ) * $centerPoint = array ( 'kind'=>'',//col,img,word 'info'=>'' ) * 没有编写完,但是思路是一样的 */ if($point['kind'] == 'col'){ $R1 = $point['info']['0']['R']; $G1 = $point['info']['0']['G']; $B1 = $point['info']['0']['B']; $R2 = $point['info']['1']['R']; $G2 = $point['info']['1']['G']; $B2 = $point['info']['1']['B']; $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2*$outerFrame; $imgH = $h + 2*$outerFrame; $base_image =ImageCreate($imgW, $imgH); $col[0] = ImageColorAllocate($base_image,$R1,$G1,$B1); $col[1] = ImageColorAllocate($base_image,$R2,$G2,$B2); imagefill($base_image, 0, 0, $col[0]); for($y=0; $y<$h; $y++) { for($x=0; $x<$w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel ($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); } } } //////////////////////x $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); ImageDestroy($base_image); return $target_image; }elseif($point['kind'] == 'img'){ function getSquare($image, $multi){ $imgW = imagesx($image); $imgH = imagesy($image); $imgMin = min($imgH,$imgW); $target_image =imagecreatetruecolor($imgMin,$imgMin); imagecopyresampled($target_image, $image, 0, 0, 0, 0, $imgMin , $imgMin, $imgW, $imgH); //ImageCopyResized($target_image, $image, 0, 0, 0, 0, $imgW * $multi, $imgH * $multi, $imgW, $imgH); $multi_image =imagecreatetruecolor($imgMin*$multi,$imgMin*$multi); imagecopyresampled($multi_image, $target_image, 0, 0, 0, 0, $imgMin*$multi,$imgMin*$multi, $imgMin, $imgMin); //ImageCopyResized($target_image, $image, 0, 0, 0, 0, $imgW * $multi, $imgH * $multi, $imgW, $imgH); ImageDestroy($image); return $multi_image; } function getSameSize($image,$pixelPerPoint){ $imgW = imagesx($image); $imgH = imagesy($image); $target_image =imagecreatetruecolor($pixelPerPoint,$pixelPerPoint); ImageCopyResized($target_image, $image, 0, 0, 0, 0, $pixelPerPoint , $pixelPerPoint, $imgW, $imgH); //ImageCopyResized($target_image, $image, 0, 0, 0, 0, $imgW * $multi, $imgH * $multi, $imgW, $imgH); ImageDestroy($image); return $target_image; } $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2*$outerFrame; $imgH = $h + 2*$outerFrame; $base_image =ImageCreate($imgW*$pixelPerPoint, $imgH*$pixelPerPoint); imagefill($base_image, 0, 0, ImageColorAllocate($base_image,255,255,255)); $pointimg = imagecreatefromjpeg ($point['info']); $newimg = getSquare($pointimg, 1); $newimgpoint = getSameSize($newimg,$pixelPerPoint); for($y=0; $y<$h; $y++) { for($x=0; $x<$w; $x++) { if ($frame[$y][$x] == '1') { imagecopyresampled($base_image, $newimgpoint, $y*$pixelPerPoint, $x*$pixelPerPoint, 0, 0, $pixelPerPoint, $pixelPerPoint, $pixelPerPoint, $pixelPerPoint); } } } return $base_image; }elseif($point['kind'] == 'word'){ }else{ $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2*$outerFrame; $imgH = $h + 2*$outerFrame; $base_image =ImageCreate($imgW, $imgH); $col[0] = ImageColorAllocate($base_image,255,255,255); $col[1] = ImageColorAllocate($base_image,0,0,0); imagefill($base_image, 0, 0, $col[0]); for($y=0; $y<$h; $y++) { for($x=0; $x<$w; $x++) { if ($frame[$y][$x] == '1') { ImageSetPixel ($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); } } } //////////////////////x $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); ImageDestroy($base_image); return $target_image; } }
At present, both corporate and personal websites, and even media platforms have posted their own QR codes. Firstly, they can cater to market demand, and secondly, they can attract everyone’s attention. Due to the continuous expansion of the demand for QR codes, there are more and more types of QR code generators on the market. However, the QR codes generated by most QR code generators are black and white, with a relatively simple appearance and no distinctive features. If you want to pursue individuality and generate colorful QR codes, you can take a look at how Sesame does it.
The QR code generated by the QR code generator that we see most in our daily life is nothing more than a regular square matrix QR code with a regular square in the upper right, upper left, and lower left. It has information acquisition (text, With functions such as business cards, maps, WIFI passwords, website addresses, text messages, and videos, Sesame QR code generator is not limited to these. Sesame QR code generator can not only generate QR codes by inputting text, business cards, website addresses, WIFI, maps, pictures, MP3, Sesame numbers and other information, but can also change the shape and color according to user preferences and even create personalized templates to generate personalized patterns and colors. QR code.
Interface for generating QR codes on Sesame.com
How to generate color QR codes on Sesame.com
1. Register as a Sesame user
2. Select text, business card, website, WIFI, map, picture, MP3 , any type of Sesame account
3. Fill in the content to be generated to generate a QR code. You can choose between ordinary QR codes and personalized templates. If you choose a normal QR code, you can choose your favorite color according to your personal preferences, add a LOGO or adjust the shape to generate a QR code; if you choose a personalized template, you can choose your favorite template to generate a personalized and fun QR code, which can be displayed in real time on the right Preview the generated QR code, and finally download the generated QR code to your local computer!
Normal QR code
Personalized template
Generating color QR code is very simple, try it now! Sodium)
There are many generator software online now, but most of them are nothing new. I recently tried the new QR code generator from Sesame.com, and I was not disappointed. The generator can adjust the color and gradient at will. , you can also adjust the shape, add a logo, and especially you can choose a personalized template to make the QR code cute and lively.

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.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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.

Atom editor mac version download
The most popular open source editor