업로드 이미지 썸네일 생성

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,006
17년 전 조회 1,035
17년 전 조회 1,846
17년 전 조회 1,586
17년 전 조회 1,850
17년 전 조회 2,636
17년 전 조회 3,021
17년 전 조회 3,215
17년 전 조회 3,321
17년 전 조회 1,458
17년 전 조회 1,416
17년 전 조회 2,248
17년 전 조회 1,971
17년 전 조회 2,288
17년 전 조회 2,813
17년 전 조회 3,261
17년 전 조회 2,362
17년 전 조회 1,629
17년 전 조회 3,202
17년 전 조회 3,069
17년 전 조회 3,043
17년 전 조회 3,913
17년 전 조회 2,584
17년 전 조회 2,404
17년 전 조회 2,653
17년 전 조회 2,894
17년 전 조회 2,609
17년 전 조회 1,449
17년 전 조회 1,894
17년 전 조회 1,487
17년 전 조회 1,909
17년 전 조회 2,508
17년 전 조회 8,693
17년 전 조회 3,151
17년 전 조회 4,241
17년 전 조회 1,981
17년 전 조회 3,657
17년 전 조회 1,551
17년 전 조회 1,384
17년 전 조회 2,320
17년 전 조회 1,313
17년 전 조회 1,627
17년 전 조회 1,460
17년 전 조회 2,530
17년 전 조회 1,496
17년 전 조회 1,088
17년 전 조회 1,222
17년 전 조회 3,098
17년 전 조회 2,162
17년 전 조회 1,968
17년 전 조회 1,212
17년 전 조회 2,447
17년 전 조회 1,167
17년 전 조회 1,127
17년 전 조회 1,373
17년 전 조회 2,737
17년 전 조회 2,392
17년 전 조회 2,478
17년 전 조회 1,177
17년 전 조회 1,295
17년 전 조회 3,243
17년 전 조회 2,828
17년 전 조회 4,096
17년 전 조회 2,258
17년 전 조회 2,353
17년 전 조회 1,402
17년 전 조회 2,520
17년 전 조회 2,207
17년 전 조회 2,966
17년 전 조회 2,475
17년 전 조회 1,639
17년 전 조회 2,431
17년 전 조회 1,588
17년 전 조회 1,174
17년 전 조회 2,236
17년 전 조회 2,881
17년 전 조회 4,056
17년 전 조회 3,146
17년 전 조회 1,414
17년 전 조회 1,706
17년 전 조회 2,245
17년 전 조회 1,547
17년 전 조회 1,722
17년 전 조회 2,716
17년 전 조회 2,139
17년 전 조회 1,793
17년 전 조회 4,198
17년 전 조회 3,044
17년 전 조회 1,437
17년 전 조회 3,570
17년 전 조회 2,798
17년 전 조회 2,077
17년 전 조회 1,294
17년 전 조회 2,330
17년 전 조회 2,066
17년 전 조회 1,981
17년 전 조회 1,922
17년 전 조회 1,174
17년 전 조회 1,878
17년 전 조회 2,931
🐛 버그신고