function createsmallimg($dir,$source_img,$small_ex="_s") {
$img_name=substr($source_img,0,-4);
$img_ex = strtolower(substr(strrchr($source_img,"."),1));
/*注释的这段用作直接在浏览器上显示图片
$im=imagecreatefromjpeg($file);
header("Content-type: image/jpeg");
imagejpeg($im);*/
switch($img_ex){
case "jpg":
$src_img=ImageCreateFromJpeg($dir.$source_img);
break;
case "gif":
$src_img=ImageCreateFromGif($dir.$source_img);
break;
}
$maxheight="100";
$old_width=imagesx($src_img);
$old_height=imagesy($src_img);
if($maxheight>=$maxheight) {
$new_height=$maxheight;
$new_width=($new_height*$old_width)/$old_height;
}
if($img_ex=="jpg"){
$dst_img=imagecreatetruecolor($new_width,$new_height);
}else{
$dst_img=imagecreate($new_width,$new_height);
}
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_width,$new_height,$old_width,$old_height);
$smallname=$dir.$img_name.$small_ex.".".$img_ex;
switch($img_ex) {
case "jpg":
ImageJpeg($dst_img,$smallname,100);
break;
case "gif":
imageGif($dst_img,$smallname,100);
break;
}
}
阅读(2084) | 评论(0) | 转发(0) |