Chinaunix

标题: 用GD生成缩略图 [打印本页]

作者: gydoesit    时间: 2006-01-13 17:11
标题: 用GD生成缩略图
转的,原文地址不见了
$small_image_name="image_name";
// 生成图片的宽度
$resizewidth=400;
// 生成图片的高度
$resizeheight=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){
$resizewidth = false;
$resizeheight = false;
$widthratio = 0;
$heightratio = 0;
    $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
if(!empty($_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("$small_image_name.jpg")){
            unlink("$small_image_name.jpg");
        }
        ResizeImage($im,$resizewidth,$resizeheight,$small_image_name);
        ImageDestroy ($im);
    }
}
?>
">


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4891/showart_67662.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2