업로드 이미지 썸네일 생성

function thumbnail($file, $save_filename, $max_width, $max_height){
 $src_img = ImageCreateFromJPEG($file); //JPG파일로부터 이미지를 읽어옵니다
 $img_info = getImageSize($file);//원본이미지의 정보를 얻어옵니다
 $img_width = $img_info[0];
 $img_height = $img_info[1];
 if(($img_width/$max_width) == ($img_height/$max_height)){
  $dst_width=$max_width;
  $dst_height=$max_height;
 }elseif(($img_width/$max_width) < ($img_height/$max_height)){
  $dst_width=$max_height*($img_width/$img_height);
  $dst_height=$max_height;
 }else{
  $dst_width=$max_width;
  $dst_height=$max_width*($img_height/$img_width);
 }
 $dst_img = imagecreatetruecolor($dst_width, $dst_height); //타겟이미지를 생성합니다
 ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
 ImageInterlace($dst_img);
 ImageJPEG($dst_img,  $save_filename); //실제로 이미지파일을 생성합니다
 ImageDestroy($dst_img);
 ImageDestroy($src_img);
}

//사용 예문
if($_FILES['Filedata']['name']){
  $uploadDir1="../b_img/temp/"; //원본
  $uploadDir2="../b_img/$reg_date/"; //썸네일
  $uploadFile1="$uploadDir1".iconv("utf-8","euc-kr",$_FILES['Filedata']['name']); //원본경로
  $uploadFile2="$uploadDir2".iconv("utf-8","euc-kr",$_FILES['Filedata']['name']);  //썸네일경로
  //$uploadFile = "$uploadDir". basename($_FILES['Filedata']['name']);
  move_uploaded_file($_FILES['Filedata']['tmp_name'],$uploadFile1);
  chmod($uploadFile1,0707);
  chmod($uploadFile2,0707); 
  thumbnail($uploadFile1,$uploadFile2,"180","135");  
 }

[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]
|

댓글 1개

우와 대단합니다.찾던게 이거였는데... 테스트 해봐야 겠네요.
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
17년 전 조회 3,014
17년 전 조회 1,047
17년 전 조회 1,856
17년 전 조회 1,599
17년 전 조회 1,859
17년 전 조회 2,649
17년 전 조회 3,030
17년 전 조회 3,226
17년 전 조회 3,333
17년 전 조회 1,467
17년 전 조회 1,426
17년 전 조회 2,261
17년 전 조회 1,984
17년 전 조회 2,296
17년 전 조회 2,822
17년 전 조회 3,270
17년 전 조회 2,371
17년 전 조회 1,639
17년 전 조회 3,211
17년 전 조회 3,077
17년 전 조회 3,051
17년 전 조회 3,920
17년 전 조회 2,594
17년 전 조회 2,414
17년 전 조회 2,665
17년 전 조회 2,901
17년 전 조회 2,618
17년 전 조회 1,461
17년 전 조회 1,906
17년 전 조회 1,496
17년 전 조회 1,922
17년 전 조회 2,520
17년 전 조회 8,701
17년 전 조회 3,162
17년 전 조회 4,250
17년 전 조회 1,987
17년 전 조회 3,667
17년 전 조회 1,559
17년 전 조회 1,392
17년 전 조회 2,331
17년 전 조회 1,323
17년 전 조회 1,639
17년 전 조회 1,474
17년 전 조회 2,540
17년 전 조회 1,506
17년 전 조회 1,097
17년 전 조회 1,232
17년 전 조회 3,107
17년 전 조회 2,171
17년 전 조회 1,979
17년 전 조회 1,223
17년 전 조회 2,455
17년 전 조회 1,175
17년 전 조회 1,136
17년 전 조회 1,384
17년 전 조회 2,747
17년 전 조회 2,400
17년 전 조회 2,488
17년 전 조회 1,188
17년 전 조회 1,305
17년 전 조회 3,251
17년 전 조회 2,834
17년 전 조회 4,105
17년 전 조회 2,268
17년 전 조회 2,362
17년 전 조회 1,414
17년 전 조회 2,533
17년 전 조회 2,220
17년 전 조회 2,974
17년 전 조회 2,486
17년 전 조회 1,646
17년 전 조회 2,438
17년 전 조회 1,596
17년 전 조회 1,184
17년 전 조회 2,243
17년 전 조회 2,889
17년 전 조회 4,068
17년 전 조회 3,155
17년 전 조회 1,423
17년 전 조회 1,709
17년 전 조회 2,251
17년 전 조회 1,556
17년 전 조회 1,731
17년 전 조회 2,722
17년 전 조회 2,150
17년 전 조회 1,802
17년 전 조회 4,206
17년 전 조회 3,055
17년 전 조회 1,447
17년 전 조회 3,574
17년 전 조회 2,808
17년 전 조회 2,086
17년 전 조회 1,304
17년 전 조회 2,343
17년 전 조회 2,074
17년 전 조회 1,992
17년 전 조회 1,937
17년 전 조회 1,185
17년 전 조회 1,891
17년 전 조회 2,942
🐛 버그신고