function?img_create_small($big_img,?$width,?$height,?$small_img)?{?// 大圖文件地址,縮略寬,縮略高,小圖地址
$imgage?=?getimagesize($big_img);?//獲取大圖信息
switch?($imgage[2])?{?// 判斷圖像類型
case?1:
$im?=?imagecreatefromgif($big_img);
break;
case?2:
$im?=?imagecreatefromjpeg($big_img);
break;
case?3:
$im?=?imagecreatefrompng($big_img);
break;
}
$src_W?=?$imgage[0];?//獲取大圖寬
$src_H?=?$imgage[1];?//獲取大圖高
$tn?=?imagecreatetruecolor($width,?$height);?//創建小圖
imagecopyresampled($tn,?$im,?0,?0,?0,?0,?$width,?$height,?$src_W,?$src_H);?//復制圖像并改變大小
imagejpeg($tn,?$small_img);?//輸出圖像
}
轉載于:https://www.cnblogs.com/gaohj/p/3165289.html