非常简单PHP缩略图生成程序源代码
2010-04-17 11:17
459 查看
<?$FILENAME="image_name";
// 生成图片的宽度
$RESIZEWIDTH=400;
// 生成图片的高度
$RESIZEHEIGHT=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
www.phperz.com
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$name . ".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$name . ".jpg");
}
}
if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$FILENAME.jpg")){
unlink("$FILENAME.jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); www~phperz~com
ImageDestroy ($im);
}
}
?>
<img src="<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br>
<form enctype="multipart/form-data" method="post">
<br>
<input type="file" name="image" size="50" value="浏览"><p>
<input type="submit" value="上传图片">
</form>
</body>
</html>
文章来源 源点网
http://www.yd105.com/web/php/2010/0329/10.html
相关文章推荐
- php进行图片裁剪及生成缩略图程序源代码
- php进行图片裁剪及生成缩略图程序源代码
- PHP缩略图生成程序
- 智能的php缩略图生成程序
- 用 PIL 写了个简单的缩略图生成程序
- 一个简单的PHP生成缩略图函数
- php简单生成缩略图方法
- PHP生成缩略图(1)--简单缩略图
- 一个简单的PHP生成缩略图函数
- 帮同学写的一个简单地随机数学题生成程序,非常简单,适合练手
- PHP做视频网站,让程序自动实现视频格式转换、设置视频大小、生成视频缩略图
- PHP简单生成缩略图相册的方法
- [转]PHP上传并生成缩略图程序
- 用 PIL 写了个简单的缩略图生成程序
- 用 PIL 写了个简单的缩略图生成程序
- 一个简单的php图形验证码生成程序
- 用 PIL 写了个简单的缩略图生成程序
- PHP生成图片缩略图源代码
- 一个简单的php图形验证码生成程序
- php超全缩略图生成程序