업로드 이미지 썸네일 생성

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,059
17년 전 조회 1,091
17년 전 조회 1,905
17년 전 조회 1,657
17년 전 조회 1,906
17년 전 조회 2,692
17년 전 조회 3,084
17년 전 조회 3,269
17년 전 조회 3,377
17년 전 조회 1,519
17년 전 조회 1,476
17년 전 조회 2,309
17년 전 조회 2,031
17년 전 조회 2,352
17년 전 조회 2,871
17년 전 조회 3,324
17년 전 조회 2,417
17년 전 조회 1,685
17년 전 조회 3,265
17년 전 조회 3,122
17년 전 조회 3,105
17년 전 조회 3,966
17년 전 조회 2,641
17년 전 조회 2,460
17년 전 조회 2,706
17년 전 조회 2,947
17년 전 조회 2,668
17년 전 조회 1,505
17년 전 조회 1,945
17년 전 조회 1,534
17년 전 조회 1,968
17년 전 조회 2,568
17년 전 조회 8,747
17년 전 조회 3,213
17년 전 조회 4,304
17년 전 조회 2,044
17년 전 조회 3,718
17년 전 조회 1,617
17년 전 조회 1,435
17년 전 조회 2,379
17년 전 조회 1,362
17년 전 조회 1,684
17년 전 조회 1,525
17년 전 조회 2,588
17년 전 조회 1,553
17년 전 조회 1,148
17년 전 조회 1,281
17년 전 조회 3,156
17년 전 조회 2,217
17년 전 조회 2,019
17년 전 조회 1,275
17년 전 조회 2,494
17년 전 조회 1,217
17년 전 조회 1,187
17년 전 조회 1,439
17년 전 조회 2,797
17년 전 조회 2,450
17년 전 조회 2,535
17년 전 조회 1,234
17년 전 조회 1,350
17년 전 조회 3,306
17년 전 조회 2,888
17년 전 조회 4,159
17년 전 조회 2,312
17년 전 조회 2,420
17년 전 조회 1,473
17년 전 조회 2,579
17년 전 조회 2,268
17년 전 조회 3,018
17년 전 조회 2,530
17년 전 조회 1,699
17년 전 조회 2,488
17년 전 조회 1,646
17년 전 조회 1,237
17년 전 조회 2,290
17년 전 조회 2,934
17년 전 조회 4,116
17년 전 조회 3,206
17년 전 조회 1,471
17년 전 조회 1,737
17년 전 조회 2,296
17년 전 조회 1,600
17년 전 조회 1,783
17년 전 조회 2,764
17년 전 조회 2,196
17년 전 조회 1,847
17년 전 조회 4,258
17년 전 조회 3,100
17년 전 조회 1,496
17년 전 조회 3,623
17년 전 조회 2,859
17년 전 조회 2,126
17년 전 조회 1,356
17년 전 조회 2,392
17년 전 조회 2,124
17년 전 조회 2,038
17년 전 조회 1,987
17년 전 조회 1,238
17년 전 조회 1,939
17년 전 조회 2,986