Home > Article > Backend Development > Modify the PHP program that obtains the verification code image to the local_PHP tutorial
The recent project is not very big, so there is room for time comparison. Yesterday I was thinking about writing something. I remembered the telecom company’s voting for Smiling Angels a few days ago. Voting requires filling in a verification code. I thought about it. I wanted to write a voting cheating program, but when I came back from vacation, the event was over. I suddenly remembered yesterday and wrote a PHP program to get the verification code image to the local area, so that I can use it directly in case of similar voting activities in the future. use.
The program uses PHP's GD library. The principle is very simple, that is, first create a blank picture, and then use the imagecreatefromjpeg function in the PHP GD library to create an image object with the verification code picture. Finally, calculate the length and width of the picture, and again Use PHP's built-in imagecopy to copy to the blank image created at the beginning.
All codes are as follows:
The code here supports the verification code format as jpg. If it is in png or gif format, please refer to the second page.
Through the previous pagea PHP program that obtains verification code images locally, images with verification codes in jpg format can be output normally, but verification codes with png and gif cannot be used normally. Today I will slightly modify the PHP code so that it can support verification codes in three formats: png, gif, and jpg.
PHP can use PHP’s built-in exif_imagetype function to determine the format of the image, which is very convenient,
For detailed usage of exif_imagetype, please visit: http://php.net/manual/en/function.exif-imagetype.php
Code:
Copy to ClipboardQuoted content: [www.bkjia.com] header("Content-type:image/png");