萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> PHP獲取遠程驗證碼到本地的PHP函數代碼

PHP獲取遠程驗證碼到本地的PHP函數代碼

   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'];

  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?>

copyright © 萬盛學電腦網 all rights reserved