php获取验证码图片到本地,支持png、gif、jpg三种格式的验证码。在实现时,php判断图片格式是使用的php内置的exif_imagetype函数,确实比较方便,学习php的不妨可参考下本代码:
view sourceprint?01
02header("Content-type:image/png");
03set_time_limit(0);//设置超时时间
04$url = $_GET['url'];
立即学习“PHP免费学习笔记(深入)”;
05$url = "http://vcer.baidu.com/verify";
06if(empty($url)){
07 echo "没有图片";
08 die;
09}
10$imginfo = GetImageSize ( $url );
11$type = exif_imagetype($url);
12$imgw = $imginfo [0];
13$imgh = $imginfo [1];
14$bg = imagecreatetruecolor($imgw,$imgh);
15if($type==IMAGETYPE_GIF){
16 $image = imagecreatefromgif($url);
17}elseif($type==IMAGETYPE_JPEG){
18 $image = imagecreatefromjpeg($url);
19}elseif($type==IMAGETYPE_PNG){
20 $image = imagecreatefrompng($url);
21}
22imagecolorallocate($image,255,255,255);
23imagecopy($bg,$image,0,0, 0,0,$imgw,$imgh);
24imagedestroy($image);
25ImagePng($bg);
26?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号