Php generates Verification Code image learning notes

Source: Internet
Author: User
Tags imagecopy

Here is the learning notes generated by the Verification Code graphics during your learning. After deep learning, you can obtain remote images to your local device. However, you need to enable the php gd library here.

The Code is as follows: Copy code

Header ("Content-type: image/png ");
Set_time_limit (0); // set the PHP timeout value.
$ 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 );
Image colorallocate ($ image, 255,255,255 );
Imagecopy ($ bg, $ image, 0, 0, 0, $ imgw, $ imgh );
Imagedestroy ($ image );
ImagePng ($ bg );

Obtain the remote verification code to the local device.

The Code is as follows: Copy code

Header ("Content-type: image/png ");
Set_time_limit (0); // set the PHP timeout value.
$ Url = $ _ GET ['url'];
$ Url = "http://vcer.baidu.com/verify ";
If (empty ($ url )){
Echo "no image ";
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 );
}
 
Image colorallocate ($ image, 255,255,255 );
Imagecopy ($ bg, $ image, 0, 0, 0, $ imgw, $ imgh );
Imagedestroy ($ image );
ImagePng ($ bg );

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.