Recent projects are not very large, so the time to compare the space, yesterday, thinking about writing something, think of a few days ago, the telecommunications company voted to choose a smile angel activities, vote is to fill in the verification code, think of the next want to write a vote cheating program, but I returned home, people activities have ended, yesterday suddenly remembered, Wrote a code to get a picture of the local PHP program, in order to have a similar vote in the future can be used directly.
The program uses the PHP GD library, the principle is very simple, is to create a blank image, and then the verification code of the image using the PHP imagecreatefromjpeg function in the GD library to create an image object, and finally calculate the length and width of the picture, Use PHP's built-in imagecopy again to copy to a blank image that was created at the beginning.
The full code is as follows:
Copy to ClipboardWhat to refer to: [www.bkjia.com]Header ("Content-type:image/png");
Set_time_limit (0);//Set PHP time-out
$url = $_get[' url '];
$url = "Http://vcer.baidu.com/verify";
$imginfo = getimagesize ($url);
$IMGW = $imginfo [0];
$IMGH = $imginfo [1];
$BG = Imagecreatetruecolor ($IMGW, $IMGH);
$image = Imagecreatefromjpeg ($url);
Imagecolorallocate ($image, 255,255,255);
Imagecopy ($BG, $image, 0,0, 0,0, $IMGW, $IMGH);
Imagedestroy ($image);
Imagepng ($BG);
The code here supports the format JPG format, if it is PNG or GIF format can refer to the second page.
Through the previous page to get a verification code picture to the local PHP program , for the verification code JPG format of the picture can be normal output, for PNG, GIF verification code is not normal use, today slightly modified PHP code, so that it can support PNG, GIF, JPG Three-format verification code.
PHP determines the format of the image can use PHP built-in exif_imagetype function, very convenient,
Detailed usage of exif_imagetype can be accessed by: http://php.net/manual/en/function.exif-imagetype.php
Code:
Copy to ClipboardWhat to refer to: [www.bkjia.com]Header ("Content-type:image/png");
Set_time_limit (0);//Set PHP time-out
$url = $_get[' url '];
$url = "Http://vcer.baidu.com/verify";
if (empty ($url)) {
echo "No picture";
Die
}
$imginfo = getimagesize ($url);
$type = Exif_imagetype ($url);
$IMGW = $imginfo [0];
$IMGH = $imginfo [1];
$BG = Imagecreatetruecolor ($IMGW, $IMGH);
if ($type ==imagetype_gif) {
$image = Imagecreatefromgif ($url);
}elseif ($type ==imagetype_jpeg) {
$image = Imagecreatefromjpeg ($url);
}elseif ($type ==imagetype_png) {
$image = Imagecreatefrompng ($url);
}
Imagecolorallocate ($image, 255,255,255);
Imagecopy ($BG, $image, 0,0, 0,0, $IMGW, $IMGH);
Imagedestroy ($image);
Imagepng ($BG);
http://www.bkjia.com/PHPjc/364713.html www.bkjia.com true http://www.bkjia.com/PHPjc/364713.html techarticle Recent projects are not very large, so the time to compare the space, yesterday, thinking about writing something, think of a few days ago, the telecommunications company voted to choose the Smile Angel activities, voting is to fill in the verification code, ...