2012. 3. 21. 02:51
나름대루 썸네일 함수를 만들어 봤습니다. 잘 되더군염..
gif, jpg, png 파일이 가능하구염..

function thumnail($file, $save_filename, $save_path, $max_width, $max_height) {

// 전송받은 이미지 정보를 받는다
$img_info = getImageSize($file);

// 전송받은 이미지의 포맷값 얻기 (gif, jpg png)
if($img_info[2] == 1) {
$src_img = ImageCreateFromGif($file);
} else if($img_info[2] == 2) {
$src_img = ImageCreateFromJPEG($file);
} else if($img_info[2] == 3) {
$src_img = ImageCreateFromPNG($file);
} else {
return 0;
}

// 전송받은 이미지의 실제 사이즈 값얻기
$img_width = $img_info[0];
$img_height = $img_info[1];

if($img_width <= $max_width) {
$max_width = $img_width;
$max_height = $img_height;
}

if($img_width > $max_width){
$max_height = ceil(($max_width / $img_width) * $img_height);
}

// 새로운 트루타입 이미지를 생성
$dst_img = imagecreatetruecolor($max_width, $max_height);

// R255, G255, B255 값의 색상 인덱스를 만든다
ImageColorAllocate($dst_img, 255, 255, 255);

// 이미지를 비율별로 만든후 새로운 이미지 생성
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_width, $max_height, ImageSX($src_img),ImageSY($src_img));

// 알맞는 포맷으로 저장
if($img_info[2] == 1) {
ImageInterlace($dst_img);
ImageGif($dst_img, $save_path.$save_filename);
} else if($img_info[2] == 2) {
ImageInterlace($dst_img);
ImageJPEG($dst_img, $save_path.$save_filename);
} else if($img_info[2] == 3) {
ImagePNG($dst_img, $save_path.$save_filename);
}

// 임시 이미지 삭제
ImageDestroy($dst_img);
ImageDestroy($src_img);
Posted by k1rha