업로드 이미지 썸네일 생성

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,021
17년 전 조회 1,051
17년 전 조회 1,863
17년 전 조회 1,608
17년 전 조회 1,862
17년 전 조회 2,655
17년 전 조회 3,038
17년 전 조회 3,233
17년 전 조회 3,340
17년 전 조회 1,477
17년 전 조회 1,433
17년 전 조회 2,269
17년 전 조회 1,992
17년 전 조회 2,305
17년 전 조회 2,832
17년 전 조회 3,278
17년 전 조회 2,375
17년 전 조회 1,649
17년 전 조회 3,220
17년 전 조회 3,083
17년 전 조회 3,059
17년 전 조회 3,926
17년 전 조회 2,602
17년 전 조회 2,424
17년 전 조회 2,673
17년 전 조회 2,911
17년 전 조회 2,627
17년 전 조회 1,468
17년 전 조회 1,915
17년 전 조회 1,507
17년 전 조회 1,929
17년 전 조회 2,525
17년 전 조회 8,708
17년 전 조회 3,169
17년 전 조회 4,263
17년 전 조회 1,996
17년 전 조회 3,674
17년 전 조회 1,571
17년 전 조회 1,401
17년 전 조회 2,340
17년 전 조회 1,328
17년 전 조회 1,648
17년 전 조회 1,480
17년 전 조회 2,546
17년 전 조회 1,516
17년 전 조회 1,105
17년 전 조회 1,238
17년 전 조회 3,117
17년 전 조회 2,178
17년 전 조회 1,985
17년 전 조회 1,230
17년 전 조회 2,461
17년 전 조회 1,185
17년 전 조회 1,140
17년 전 조회 1,392
17년 전 조회 2,759
17년 전 조회 2,408
17년 전 조회 2,495
17년 전 조회 1,196
17년 전 조회 1,314
17년 전 조회 3,257
17년 전 조회 2,846
17년 전 조회 4,115
17년 전 조회 2,275
17년 전 조회 2,371
17년 전 조회 1,423
17년 전 조회 2,541
17년 전 조회 2,223
17년 전 조회 2,985
17년 전 조회 2,494
17년 전 조회 1,652
17년 전 조회 2,447
17년 전 조회 1,604
17년 전 조회 1,190
17년 전 조회 2,250
17년 전 조회 2,898
17년 전 조회 4,073
17년 전 조회 3,161
17년 전 조회 1,427
17년 전 조회 1,711
17년 전 조회 2,257
17년 전 조회 1,563
17년 전 조회 1,738
17년 전 조회 2,731
17년 전 조회 2,153
17년 전 조회 1,811
17년 전 조회 4,213
17년 전 조회 3,060
17년 전 조회 1,454
17년 전 조회 3,586
17년 전 조회 2,813
17년 전 조회 2,093
17년 전 조회 1,311
17년 전 조회 2,350
17년 전 조회 2,084
17년 전 조회 1,997
17년 전 조회 1,943
17년 전 조회 1,192
17년 전 조회 1,895
17년 전 조회 2,950