업로드 이미지 썸네일 생성

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,043
17년 전 조회 1,852
17년 전 조회 1,593
17년 전 조회 1,857
17년 전 조회 2,646
17년 전 조회 3,025
17년 전 조회 3,223
17년 전 조회 3,329
17년 전 조회 1,465
17년 전 조회 1,424
17년 전 조회 2,255
17년 전 조회 1,981
17년 전 조회 2,292
17년 전 조회 2,821
17년 전 조회 3,268
17년 전 조회 2,369
17년 전 조회 1,637
17년 전 조회 3,209
17년 전 조회 3,075
17년 전 조회 3,049
17년 전 조회 3,918
17년 전 조회 2,591
17년 전 조회 2,411
17년 전 조회 2,662
17년 전 조회 2,898
17년 전 조회 2,615
17년 전 조회 1,458
17년 전 조회 1,901
17년 전 조회 1,496
17년 전 조회 1,917
17년 전 조회 2,517
17년 전 조회 8,699
17년 전 조회 3,159
17년 전 조회 4,249
17년 전 조회 1,987
17년 전 조회 3,661
17년 전 조회 1,559
17년 전 조회 1,390
17년 전 조회 2,326
17년 전 조회 1,321
17년 전 조회 1,634
17년 전 조회 1,469
17년 전 조회 2,537
17년 전 조회 1,504
17년 전 조회 1,095
17년 전 조회 1,229
17년 전 조회 3,103
17년 전 조회 2,164
17년 전 조회 1,977
17년 전 조회 1,219
17년 전 조회 2,452
17년 전 조회 1,172
17년 전 조회 1,131
17년 전 조회 1,379
17년 전 조회 2,744
17년 전 조회 2,399
17년 전 조회 2,485
17년 전 조회 1,183
17년 전 조회 1,302
17년 전 조회 3,247
17년 전 조회 2,832
17년 전 조회 4,102
17년 전 조회 2,265
17년 전 조회 2,358
17년 전 조회 1,409
17년 전 조회 2,530
17년 전 조회 2,214
17년 전 조회 2,972
17년 전 조회 2,485
17년 전 조회 1,644
17년 전 조회 2,436
17년 전 조회 1,593
17년 전 조회 1,181
17년 전 조회 2,242
17년 전 조회 2,889
17년 전 조회 4,063
17년 전 조회 3,151
17년 전 조회 1,419
17년 전 조회 1,707
17년 전 조회 2,248
17년 전 조회 1,553
17년 전 조회 1,729
17년 전 조회 2,719
17년 전 조회 2,147
17년 전 조회 1,801
17년 전 조회 4,203
17년 전 조회 3,051
17년 전 조회 1,444
17년 전 조회 3,573
17년 전 조회 2,802
17년 전 조회 2,081
17년 전 조회 1,302
17년 전 조회 2,337
17년 전 조회 2,072
17년 전 조회 1,988
17년 전 조회 1,933
17년 전 조회 1,182
17년 전 조회 1,889
17년 전 조회 2,939
🐛 버그신고