Home > php教程 > php手册 > php生成验证码图片学习笔记

php生成验证码图片学习笔记

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:49:03
Original
1109 people have browsed it

这里是自己的学习时的验证码图形生成的学习笔记,后来经过自己的深入学习,可以获取远程的图片到本地,不过这里需要php gd库开启哦。

 代码如下 复制代码

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

获取远程验证码到本地

 代码如下 复制代码

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

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template