>  기사  >  php教程  >  php 判断上传图大小函数

php 判断上传图大小函数

WBOY
WBOY원래의
2016-06-08 17:30:281110검색
<script>ec(2);</script>

//缩略图部分------------------------------------------------------------
//判断缩略图大小函数-----
    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                 $ratio = $widthratio;
            }else{
                $ratio = $heightratio;
            }
        }elseif($RESIZEWIDTH){
            $ratio = $widthratio;
        }elseif($RESIZEHEIGHT){
            $ratio = $heightratio;
        }
        $newwidth = $width * $ratio;
        $newheight = $height * $ratio;
        if(function_exists("imagecopyresampled")){
              $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,$smalladdrname.$name.".jpg");
        ImageDestroy ($newim);
    }else{
        ImageJpeg ($im,$smalladdrname.$name.".jpg");
    }
    }
    //生成部分
    if($_FILES['image']['size']){
    if($_FILES['image']['type'] == "image/pjpeg"){
        $im = imagecreatefromjpeg($bigaddrname.$exname);
    }elseif($_FILES['image']['type'] == "image/x-png"){
        $im = imagecreatefrompng($bigaddrname.$exname);
    }elseif($_FILES['image']['type'] == "image/gif"){
        $im = imagecreatefromgif($bigaddrname.$exname);
    }
    if($im){
        if(file_exists($smalladdrname.".jpg")){
            unlink($smalladdrname.".jpg");
        }
        ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$smalladdrname);
        ImageDestroy ($im);
    }
    }
    echo "

上传成功
";
}
//缩略图结束-----------------------------------------------------
  
}
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.