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.