업로드 이미지 썸네일 생성

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,172
17년 전 조회 1,164
17년 전 조회 2,003
17년 전 조회 1,739
17년 전 조회 1,990
17년 전 조회 2,804
17년 전 조회 3,170
17년 전 조회 3,383
17년 전 조회 3,482
17년 전 조회 1,590
17년 전 조회 1,572
17년 전 조회 2,385
17년 전 조회 2,130
17년 전 조회 2,427
17년 전 조회 2,961
17년 전 조회 3,441
17년 전 조회 2,526
17년 전 조회 1,793
17년 전 조회 3,376
17년 전 조회 3,227
17년 전 조회 3,205
17년 전 조회 4,069
17년 전 조회 2,719
17년 전 조회 2,560
17년 전 조회 2,820
17년 전 조회 3,057
17년 전 조회 2,775
17년 전 조회 1,607
17년 전 조회 2,018
17년 전 조회 1,618
17년 전 조회 2,070
17년 전 조회 2,676
17년 전 조회 8,847
17년 전 조회 3,302
17년 전 조회 4,367
17년 전 조회 2,133
17년 전 조회 3,798
17년 전 조회 1,710
17년 전 조회 1,522
17년 전 조회 2,455
17년 전 조회 1,460
17년 전 조회 1,759
17년 전 조회 1,604
17년 전 조회 2,685
17년 전 조회 1,636
17년 전 조회 1,230
17년 전 조회 1,367
17년 전 조회 3,258
17년 전 조회 2,297
17년 전 조회 2,099
17년 전 조회 1,356
17년 전 조회 2,582
17년 전 조회 1,308
17년 전 조회 1,263
17년 전 조회 1,516
17년 전 조회 2,882
17년 전 조회 2,544
17년 전 조회 2,609
17년 전 조회 1,315
17년 전 조회 1,432
17년 전 조회 3,394
17년 전 조회 2,965
17년 전 조회 4,240
17년 전 조회 2,401
17년 전 조회 2,499
17년 전 조회 1,555
17년 전 조회 2,668
17년 전 조회 2,344
17년 전 조회 3,109
17년 전 조회 2,616
17년 전 조회 1,765
17년 전 조회 2,554
17년 전 조회 1,710
17년 전 조회 1,294
17년 전 조회 2,368
17년 전 조회 3,010
17년 전 조회 4,198
17년 전 조회 3,279
17년 전 조회 1,542
17년 전 조회 1,784
17년 전 조회 2,378
17년 전 조회 1,681
17년 전 조회 1,858
17년 전 조회 2,827
17년 전 조회 2,275
17년 전 조회 1,924
17년 전 조회 4,325
17년 전 조회 3,170
17년 전 조회 1,567
17년 전 조회 3,695
17년 전 조회 2,933
17년 전 조회 2,199
17년 전 조회 1,426
17년 전 조회 2,465
17년 전 조회 2,195
17년 전 조회 2,107
17년 전 조회 2,055
17년 전 조회 1,297
17년 전 조회 2,008
17년 전 조회 3,054