Home > Backend Development > PHP Tutorial > PHP generates verification code picture study notes_PHP tutorial

PHP generates verification code picture study notes_PHP tutorial

WBOY
Release: 2016-07-13 10:46:15
Original
861 people have browsed it

Here are the study notes generated by the verification code graphics when I was studying. Later, after my own in-depth study, I can get the remote pictures to the local, but here I need to open the php gd library.

The code is as follows
 代码如下 复制代码

header("Content-type:image/png");
set_time_limit(0);//设置PHP超时时间
$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);

Copy code

 代码如下 复制代码

header("Content-type:image/png");
set_time_limit(0);//设置PHP超时时间
$url = $_GET['url'];
$url = "http://vcer.baidu.com/verify";
if(empty($url)){
 echo "没有图片";
 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);

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);

Get the remote verification code locally

The code is as follows Copy code
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 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/632966.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632966.htmlTechArticleHere are the study notes generated by the verification code graphics during my study. Later, after my own in-depth study, I can obtain Remote pictures are sent to the local one, but the php gd library needs to be enabled here. ...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template