업로드 이미지 썸네일 생성

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,000
17년 전 조회 1,031
17년 전 조회 1,841
17년 전 조회 1,582
17년 전 조회 1,843
17년 전 조회 2,633
17년 전 조회 3,017
17년 전 조회 3,210
17년 전 조회 3,316
17년 전 조회 1,453
17년 전 조회 1,410
17년 전 조회 2,242
17년 전 조회 1,965
17년 전 조회 2,281
17년 전 조회 2,804
17년 전 조회 3,258
17년 전 조회 2,356
17년 전 조회 1,626
17년 전 조회 3,198
17년 전 조회 3,064
17년 전 조회 3,038
17년 전 조회 3,906
17년 전 조회 2,579
17년 전 조회 2,399
17년 전 조회 2,649
17년 전 조회 2,887
17년 전 조회 2,606
17년 전 조회 1,446
17년 전 조회 1,890
17년 전 조회 1,483
17년 전 조회 1,906
17년 전 조회 2,503
17년 전 조회 8,688
17년 전 조회 3,148
17년 전 조회 4,235
17년 전 조회 1,978
17년 전 조회 3,654
17년 전 조회 1,546
17년 전 조회 1,380
17년 전 조회 2,317
17년 전 조회 1,309
17년 전 조회 1,623
17년 전 조회 1,453
17년 전 조회 2,522
17년 전 조회 1,491
17년 전 조회 1,082
17년 전 조회 1,217
17년 전 조회 3,093
17년 전 조회 2,157
17년 전 조회 1,965
17년 전 조회 1,207
17년 전 조회 2,442
17년 전 조회 1,165
17년 전 조회 1,123
17년 전 조회 1,364
17년 전 조회 2,727
17년 전 조회 2,384
17년 전 조회 2,470
17년 전 조회 1,172
17년 전 조회 1,286
17년 전 조회 3,236
17년 전 조회 2,823
17년 전 조회 4,088
17년 전 조회 2,249
17년 전 조회 2,345
17년 전 조회 1,393
17년 전 조회 2,514
17년 전 조회 2,201
17년 전 조회 2,959
17년 전 조회 2,467
17년 전 조회 1,631
17년 전 조회 2,425
17년 전 조회 1,582
17년 전 조회 1,171
17년 전 조회 2,232
17년 전 조회 2,877
17년 전 조회 4,052
17년 전 조회 3,141
17년 전 조회 1,408
17년 전 조회 1,706
17년 전 조회 2,238
17년 전 조회 1,543
17년 전 조회 1,716
17년 전 조회 2,710
17년 전 조회 2,133
17년 전 조회 1,787
17년 전 조회 4,188
17년 전 조회 3,039
17년 전 조회 1,429
17년 전 조회 3,561
17년 전 조회 2,792
17년 전 조회 2,073
17년 전 조회 1,289
17년 전 조회 2,323
17년 전 조회 2,063
17년 전 조회 1,976
17년 전 조회 1,919
17년 전 조회 1,170
17년 전 조회 1,874
17년 전 조회 2,928
🐛 버그신고