非常简单PHP缩略图生成程序源代码<br />
<?<br />
$FILENAME="image_name";// 生成图片的宽度<br />
$RESIZEWIDTH=400;// 生成图片的高度<br />
$RESIZEHEIGHT=400;<br />
function ResizeImage($im,$maxwidth,$maxheight,$name){<br />
$width = imagesx($im);<br />
$height = imagesy($im);<br />
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){<br />
if($maxwidth && $width > $maxwidth){<br />
$widthratio = $maxwidth/$width;<br />
$RESIZEWIDTH=true;<br />
}<br />
if($maxheight && $height > $maxheight){<br />
$heightratio = $maxheight/$height;<br />
$RESIZEHEIGHT=true;<br />
}<br />
if($RESIZEWIDTH && $RESIZEHEIGHT){<br />
if($widthratio < $heightratio){<br />
$ratio = $widthratio;<br />
}else{<br />
$ratio = $heightratio;<br />
}<br />
}elseif($RESIZEWIDTH){<br />
$ratio = $widthratio;<br />
}elseif($RESIZEHEIGHT){<br />
$ratio = $heightratio;<br />
}<br />
$newwidth = $width * $ratio;<br />
$newheight = $height * $ratio;<br />
if(function_exists("imagecopyresampled")){ www.phperz.com<br />
$newim = imagecreatetruecolor($newwidth, $newheight);<br />
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);<br />
}else{<br />
$newim = imagecreate($newwidth, $newheight);<br />
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);<br />
}<br />
ImageJpeg ($newim,$name . ".jpg");<br />
ImageDestroy ($newim);<br />
}else{<br />
ImageJpeg ($im,$name . ".jpg");<br />
}<br />
}<br />
<br />
if($_FILES['image']['size']){<br />
if($_FILES['image']['type'] == "image/pjpeg"){<br />
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);<br />
}elseif($_FILES['image']['type'] == "image/x-png"){<br />
$im = imagecreatefrompng($_FILES['image']['tmp_name']);<br />
}elseif($_FILES['image']['type'] == "image/gif"){<br />
$im = imagecreatefromgif($_FILES['image']['tmp_name']);<br />
}<br />
if($im){<br />
if(file_exists("$FILENAME.jpg")){<br />
unlink("$FILENAME.jpg");<br />
}<br />
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); www~phperz~com <br />
ImageDestroy ($im);<br />
}<br />
}<br />
?><br />
<img src="<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br><br />
<form enctype="multipart/form-data" method="post"><br />
<br><br />
<input type="file" name="image" size="50" value="浏览"><p><br />
<input type="submit" value="上传图片"><br />
</form><br />
</body><br />
</html>