Personalize your own QR code and your own QR code
1. What is a QR code?
2. How to Create a QR code
3. How to create your own personalized QR code
1. Step 1. Download Php class library phpqrcode, (Appendix: http://sourceforge.net/projects/phpqrcode)
The use cases on the Internet are as follows:
<? Php/* $ errorCorrectionLevel Error Correction level: L, M, Q, H $ matrixPointSize indicates the pixel size of each black spot in the image: 1 to 10 */include '/phpqrcode. php '; // introduce the php qr code library file $ value = "personalize your own QR code"; // QR code data $ errorCorrectionLevel = "l"; // Error Correction level: l, M, Q, H $ matrixPointSize = "10"; // The point size: 1 to 10 QRcode: png ($ value, false, $ errorCorrectionLevel ); exit;?>
2. Read the above Code
What makes the above Code a wonderful journey?
Let me open phpqrcode. php and take a look. The code is too long to be pasted. You can download it yourself.
Take a look at the above Code and phpqrcode. php:
<? Php/* $ errorCorrectionLevel Error Correction level: L, M, Q, H $ matrixPointSize indicates the pixel size of each black spot in the image: 1 to 10 */include 'phpqrcode/phpqrcode. php '; // introduce the php qr code library file $ intext = "personalize your own QR code"; // QR code data $ errorCorrectionLevel = "l"; // Error Correction level: l, M, Q, H $ matrixPointSize = "2"; // vertex size: 1 to 10 $ margin = 1; $ size = 10; $ outfile = false; $ saveandprint = false; $ enc = QRencode: factory ($ errorCorrectionLevel, $ size, $ margin); // $ enc-> encodePNG ($ value, false, $ saveandp Rint = false); try {ob_start (); $ tab = $ enc-> encode ($ intext); print_r ($ tab); $ err = ob_get_contents (); ob_end_clean (); if ($ err! = '') QRtools: log ($ outfile, $ err);/* mark */$ 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 an array $ tab through an algorithm, and then draws an image, that is, our QR code, through image operations.
If you print the array $ tab, you will find that it is 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 easy. You can draw images based on the array $ tab:
QRimage::png($tab, $outfile, min(max(1, $enc->size), $maxSize), $enc->margin,$saveandprint);
3. How to draw
If we look at the source code, we will find that the most critical method is:
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4);
The source code I commented out is shown below (the original class library is not commented out)
<? Phpfunction image ($ frame, $ pixelPerPoint = 4, $ outerFrame = 4) {// $ frame is an array $ tab, $ pixelPerPoint, $ outerFrame cannot tell what it is, $ h = count ($ frame); $ w = strlen ($ frame [0]); // calculates the length of the image to be drawn. $ h indicates the height, $ w indicates the width $ imgW = $ w + 2 * $ outerFrame; $ imgH = $ h + 2 * $ outerFrame; // It makes the canvas bigger! Description $ outerFrame is the surrounding white size $ base_image = ImageCreate ($ imgW, $ imgH); // imagecreate-create a palette-based image, in other words, we can now draw $ col [0] = ImageColorAllocate ($ base_image, 255,255,255) based on $ base_image; $ col [1] = ImageColorAllocate ($ base_image, 0 ); // imagecolorallocate-assign color to an image // The first parameter is set up, and the last three parameters are R, G, and B (the size ranges from 0 to 255 ), you can understand it as pigment ......, The three paints are mixed in different proportions to produce different colors, so $ col [0] is a white paint brush, $ col [1] is a black paint brush (Why do the three 255 s are white and the Three 0 s are black? You can imagine an experiment where white light can be broken down in the middle school physics ......) Imagefill ($ base_image, 0, 0, $ col [0]); // fill in the imagefill area. The entire canvas is white. 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]) ;}}// fill 1 in the $ tab array with black through two loops, the remaining 0 values are white. // $ outerFrame indicates white space. $ target_image = ImageCreate ($ imgW * $ pixelPerPoint, $ imgH * $ pixelPerPoint); // ImageCreate this function has just been introduced, why call it again ............ And the size is twice that of the original $ pixelPerPoint! // Well, $ pixelPerPoint is a magnification. Here we start to enlarge the generated image as needed (only the enlarged canvas is generated now) ImageCopyResized ($ target_image, $ base_image, 0, 0, 0, 0, $ imgW * $ pixelPerPoint, $ imgH * $ pixelPerPoint, $ imgW, $ imgH ); // imagecopyresized-copy part of the image and resize it. // zoom in the image you just created and multiply it by $ pixelPerPoint. Then copy the image to the newly created canvas ($ base_image ); // imagedestroy-destroy an image return $ target_image; // return the generated final image !}
4. Be steadfast.
So ............
(1) Can "black spots" be changed to colored points? Become love ?, Become a photo of your girlfriend? Into text?
(2) Can I add something in the middle of the image, a word of "love", or something that can express my mind?
5. compile your own Method
Private static function myImage ($ frame, $ pixelPerPoint = 4, $ outerFrame = 4, $ point, $ centerPoint) {/** array $ point indicates the style of the filled point * array $ centerPoint indicates the style of the middle part of the image * $ point = array ('kind' => '', // col, img, word 'info' => ''// rgb, filename) * $ centerPoint = array ('kind' =>'', // col, img, word 'info' => '') * not completed, but the idea is the same */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) ;}} 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); 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 ;}}
How to Do personalized QR code?
At present, no matter whether you are an enterprise or a personal website, or even a media platform, you can post your own QR code to meet the market needs, or you can get everyone's eye. As the demand for QR codes continues to expand, there are more and more types of QR code generators on the market. However, the QR code generated by most QR code generators is black and white, with a single shape and no special features. If you want to pursue your own personality and generate a color QR code, you can see how zhima net does it.
In our daily life, we see that the most common QR code generator generates a matrix QR code with a regular square on the top right, top left, and bottom left, with information acquisition (text, business card, MAP, WIFI password, URL, SMS, video) and other functions, sesame QR code generator is not limited to this. The sesame QR code generator can not only generate a QR code by entering text, business cards, URLs, WIFI, maps, images, MP3, and sesame codes, in addition, you can change the shape and color or even the personalized template to generate a QR code with personalized patterns and colors.
Sesame web QR code generation Interface
How to generate a color QR code on sesame net
1. Register as a sesame user
2. Select any type of text, business card, website address, WIFI, MAP, image, MP3, and sesame
3. Fill in the content to be generated to generate a QR code. You can select a common QR code and a personalized template. If you select a regular QR code, you can select your preferred color, add a LOGO or adjust the shape to generate a QR code. If you select a personalized template, you can select a favorite template to generate a personalized and fun QR code, the generated QR code preview is displayed on the right, and the generated QR code can be downloaded to the local device!
Common QR code
Personalized templates
It's easy to generate a color QR code. Please try it now! Sodium)
How to generate a personalized and fun QR code?
There are a lot of online generator software, but most of them are not new. Recently I tried the new QR code generator released by zhima net, which really disappointed me, the generator allows you to adjust the color and gradient at will, adjust the shape, and add the logo. In particular, you can also choose a personalized template to make the QR code cute and smart.