Use the GD library in php to generate a graphical example-PHP source code

Source: Internet
Author: User
To do QR code anti-counterfeiting for the customer, he needs to paste the QR code to the product, and then download the QR code cannot match the product one by one. Therefore, this function is required. To do QR code anti-counterfeiting for the customer, he needs to paste the QR code to the product, and then download the QR code cannot match the product one by one. Therefore, this function is required.

Script ec (2); script

Combine the QR code with the product id into a picture...
My step is to first generate a chart and put the product id in... Then combine the image of the QR code with the generated image...
Merging is actually to paste the QR code to the generated graph...
The Code is as follows:

The Code is as follows:

$ Width = 310; // The width of the canvas.

$ Height = 360; // canvas height
$ Im = imagecreate ($ width, $ height );
$ Img2 = imagecreatefrompng ("$ url"); // obtain the QR code
$ Im_WH = getimagesize ("$ url"); // obtain the attributes of the QR code image.
$ Im_W = $ im_WH [0];
$ Im_H = $ im_WH [1];
$ White = ImageColorAllocate ($ im, 255,255,255); // defines the white background color.
$ Black = ImageColorAllocate ($ im, 0); // defines the black font color.
$ Rectangelcolor = ImageColorAllocate ($ im, 150,150,150); // defines the border color.
Imagerectangle ($ im, $ width-1, $ height-1, $ rectangelcolor); // draw a border
Imagettftext ($ im, 15,330, $ black, 'c: WINDOWSFontsarial. ttf', "$ proid"); // write the product id
Imagecopy ($ im, $ img2, 5, 5, $ im_W, $ im_H); // merge two images
$ Images = mrand4B (). time (). '.jpg '; // new image name
$ Path = $ _ SERVER ['document _ root']. '/static/downloadpic/'. $ images; // image path
Imagejpeg ($ im, $ path); // generate a new graph and place it in the specified path.
Imagedestroy ($ im); // release memory
Return $ images; // The name of the image to be saved to the database.

Note that the phpgd library is disabled by default. If you fail to use the gd library, you need to enable it.

We need to remove extension = php_gd2.dll from php. ini.

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.