Home Backend Development PHP Tutorial Modify the PHP program that obtains the verification code image to the local_PHP tutorial

Modify the PHP program that obtains the verification code image to the local_PHP tutorial

Jul 21, 2016 pm 02:53 PM
php no Revise picture time yesterday local Compare of code program space Obtain project verify

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:

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] header("Content-type:image/png");
set_time_limit(0);//Set PHP timeout
$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 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 ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] header("Content-type:image/png");
set_time_limit(0);//Set PHP timeout
$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);
}

imagecolorallocate($image,255,255,255);
imagecopy ($bg,$image,0,0, 0,0,$imgw,$imgh);
imagedestroy($image);
ImagePng($bg);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364713.htmlTechArticleThe recent project is not very big, so there is no room for time comparison. Yesterday I was thinking about writing something, and I remembered a few days ago Telecommunications companies vote for Smiling Angels. To vote, you need to fill in a verification code...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles