업로드 이미지 썸네일 생성

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,013
17년 전 조회 1,045
17년 전 조회 1,853
17년 전 조회 1,595
17년 전 조회 1,858
17년 전 조회 2,648
17년 전 조회 3,028
17년 전 조회 3,225
17년 전 조회 3,331
17년 전 조회 1,466
17년 전 조회 1,425
17년 전 조회 2,260
17년 전 조회 1,984
17년 전 조회 2,294
17년 전 조회 2,822
17년 전 조회 3,268
17년 전 조회 2,370
17년 전 조회 1,638
17년 전 조회 3,210
17년 전 조회 3,075
17년 전 조회 3,051
17년 전 조회 3,918
17년 전 조회 2,593
17년 전 조회 2,414
17년 전 조회 2,663
17년 전 조회 2,900
17년 전 조회 2,617
17년 전 조회 1,458
17년 전 조회 1,902
17년 전 조회 1,496
17년 전 조회 1,920
17년 전 조회 2,518
17년 전 조회 8,701
17년 전 조회 3,161
17년 전 조회 4,249
17년 전 조회 1,987
17년 전 조회 3,664
17년 전 조회 1,559
17년 전 조회 1,391
17년 전 조회 2,329
17년 전 조회 1,323
17년 전 조회 1,635
17년 전 조회 1,472
17년 전 조회 2,537
17년 전 조회 1,506
17년 전 조회 1,097
17년 전 조회 1,232
17년 전 조회 3,104
17년 전 조회 2,168
17년 전 조회 1,978
17년 전 조회 1,221
17년 전 조회 2,455
17년 전 조회 1,174
17년 전 조회 1,132
17년 전 조회 1,383
17년 전 조회 2,746
17년 전 조회 2,399
17년 전 조회 2,487
17년 전 조회 1,186
17년 전 조회 1,303
17년 전 조회 3,249
17년 전 조회 2,834
17년 전 조회 4,105
17년 전 조회 2,268
17년 전 조회 2,360
17년 전 조회 1,412
17년 전 조회 2,533
17년 전 조회 2,218
17년 전 조회 2,973
17년 전 조회 2,485
17년 전 조회 1,645
17년 전 조회 2,437
17년 전 조회 1,596
17년 전 조회 1,182
17년 전 조회 2,242
17년 전 조회 2,889
17년 전 조회 4,065
17년 전 조회 3,153
17년 전 조회 1,419
17년 전 조회 1,708
17년 전 조회 2,249
17년 전 조회 1,555
17년 전 조회 1,731
17년 전 조회 2,720
17년 전 조회 2,148
17년 전 조회 1,802
17년 전 조회 4,204
17년 전 조회 3,052
17년 전 조회 1,445
17년 전 조회 3,574
17년 전 조회 2,806
17년 전 조회 2,082
17년 전 조회 1,304
17년 전 조회 2,339
17년 전 조회 2,074
17년 전 조회 1,990
17년 전 조회 1,935
17년 전 조회 1,183
17년 전 조회 1,889
17년 전 조회 2,940
🐛 버그신고