Personalize your own QR code, and personalize your own QR code _ PHP Tutorial

Source: Internet
Author: User
Personalize your own QR code and your own QR code. Personalize your own QR code. personalize your own QR code. 1. what is a QR code? 2. how do we make a QR code? 3. how do we make our own personalized QR code? 1. step 1. Download P to personalize 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:

 

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:

 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);/* 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)

 

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.
 

Tip 1: What is a QR code 2. how do we make a QR Code 3. how do we make our own personalized QR Code 1. step 1. Download P...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.