[PHP] - Thumbnail 함수

PHP 2011. 6. 28. 18:13
반응형

[PHP] - Make ThumbNail

################ Thumb Nail ###################

function MakeThumb($file_path, $save_path, $width){

   

    $imginfo = getimagesize($file_path);

//print_r($imginfo);

 //$imginfo[2] = "2";

    if($imginfo[2] != 1 && $imginfo[2] != 2 && $imginfo[2] != 3){

        return "확장자가 jp(e)g/png/gif 가 아닙니다.";

    }

   

    if($imginfo[2] == 1)        $getfile = imagecreatefromgif($file_path);

    else if($imginfo[2] == 2)    $getfile = imagecreatefromjpeg($file_path);

    else if($imginfo[2] == 3)    $getfile = imagecreatefrompng($file_path);

   

    $height = ( $width / $imginfo[0] ) * $imginfo[1];

    $make_img = imagecreatetruecolor($width, $height);

    imagecopyresampled($make_img, $getfile, 0, 0, 0, 0, $width, $height, $imginfo[0], $imginfo[1]);

   

    if($imginfo[2] == 1)        imagegif($make_img, $save_path, 90);    // 1~100

    else if($imginfo[2] == 2)    imagejpeg($make_img, $save_path, 90); // 1~100

    else if($imginfo[2] == 3)    imagepng($make_img, $save_path, 9);  //  1~9

   

    imagedestroy($make_img);

    return true;

}

##### Call #####

   MakeThumb($dir.$real_filename, $thumb."thumb_".$real_filename, $width);

경로 + 파일명//


반응형
: