這是斷橋殘雪寫的一篇獲取驗證碼圖片到本地的PHP程序的文章,支持png、gif、jpg三種格式的驗證碼。PHP判斷圖片的格式可使用php內(nèi)置的exif_imagetype函數(shù),非常方便,關(guān)于exif_imagetype的詳細(xì)使用方法可以訪問:http://php.net/manual/en/function.exif-imagetype.php
全部代碼如下:
header("Content-type:image/png"); set_time_limit(0);//設(shè)置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); 原文地址:http://www.js8.in/667.html