업로드 이미지 썸네일 생성

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,057
17년 전 조회 1,091
17년 전 조회 1,904
17년 전 조회 1,656
17년 전 조회 1,905
17년 전 조회 2,691
17년 전 조회 3,082
17년 전 조회 3,269
17년 전 조회 3,377
17년 전 조회 1,516
17년 전 조회 1,474
17년 전 조회 2,308
17년 전 조회 2,028
17년 전 조회 2,352
17년 전 조회 2,869
17년 전 조회 3,324
17년 전 조회 2,413
17년 전 조회 1,683
17년 전 조회 3,265
17년 전 조회 3,122
17년 전 조회 3,102
17년 전 조회 3,966
17년 전 조회 2,640
17년 전 조회 2,456
17년 전 조회 2,705
17년 전 조회 2,946
17년 전 조회 2,668
17년 전 조회 1,505
17년 전 조회 1,945
17년 전 조회 1,533
17년 전 조회 1,968
17년 전 조회 2,567
17년 전 조회 8,745
17년 전 조회 3,212
17년 전 조회 4,302
17년 전 조회 2,041
17년 전 조회 3,717
17년 전 조회 1,616
17년 전 조회 1,434
17년 전 조회 2,378
17년 전 조회 1,360
17년 전 조회 1,682
17년 전 조회 1,525
17년 전 조회 2,587
17년 전 조회 1,552
17년 전 조회 1,146
17년 전 조회 1,281
17년 전 조회 3,155
17년 전 조회 2,215
17년 전 조회 2,017
17년 전 조회 1,273
17년 전 조회 2,493
17년 전 조회 1,216
17년 전 조회 1,185
17년 전 조회 1,436
17년 전 조회 2,793
17년 전 조회 2,450
17년 전 조회 2,535
17년 전 조회 1,234
17년 전 조회 1,349
17년 전 조회 3,304
17년 전 조회 2,886
17년 전 조회 4,158
17년 전 조회 2,312
17년 전 조회 2,419
17년 전 조회 1,471
17년 전 조회 2,579
17년 전 조회 2,266
17년 전 조회 3,018
17년 전 조회 2,529
17년 전 조회 1,695
17년 전 조회 2,484
17년 전 조회 1,644
17년 전 조회 1,235
17년 전 조회 2,290
17년 전 조회 2,934
17년 전 조회 4,113
17년 전 조회 3,204
17년 전 조회 1,470
17년 전 조회 1,736
17년 전 조회 2,293
17년 전 조회 1,599
17년 전 조회 1,781
17년 전 조회 2,761
17년 전 조회 2,196
17년 전 조회 1,846
17년 전 조회 4,258
17년 전 조회 3,099
17년 전 조회 1,495
17년 전 조회 3,621
17년 전 조회 2,856
17년 전 조회 2,123
17년 전 조회 1,356
17년 전 조회 2,392
17년 전 조회 2,120
17년 전 조회 2,038
17년 전 조회 1,986
17년 전 조회 1,237
17년 전 조회 1,937
17년 전 조회 2,986