업로드 이미지 썸네일 생성

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,009
17년 전 조회 1,041
17년 전 조회 1,850
17년 전 조회 1,591
17년 전 조회 1,852
17년 전 조회 2,643
17년 전 조회 3,023
17년 전 조회 3,217
17년 전 조회 3,327
17년 전 조회 1,462
17년 전 조회 1,419
17년 전 조회 2,251
17년 전 조회 1,975
17년 전 조회 2,288
17년 전 조회 2,815
17년 전 조회 3,264
17년 전 조회 2,366
17년 전 조회 1,632
17년 전 조회 3,206
17년 전 조회 3,071
17년 전 조회 3,046
17년 전 조회 3,914
17년 전 조회 2,588
17년 전 조회 2,405
17년 전 조회 2,656
17년 전 조회 2,896
17년 전 조회 2,611
17년 전 조회 1,454
17년 전 조회 1,896
17년 전 조회 1,487
17년 전 조회 1,913
17년 전 조회 2,511
17년 전 조회 8,697
17년 전 조회 3,157
17년 전 조회 4,244
17년 전 조회 1,984
17년 전 조회 3,661
17년 전 조회 1,555
17년 전 조회 1,386
17년 전 조회 2,322
17년 전 조회 1,316
17년 전 조회 1,630
17년 전 조회 1,464
17년 전 조회 2,532
17년 전 조회 1,501
17년 전 조회 1,089
17년 전 조회 1,225
17년 전 조회 3,099
17년 전 조회 2,162
17년 전 조회 1,970
17년 전 조회 1,217
17년 전 조회 2,451
17년 전 조회 1,169
17년 전 조회 1,129
17년 전 조회 1,376
17년 전 조회 2,740
17년 전 조회 2,394
17년 전 조회 2,480
17년 전 조회 1,178
17년 전 조회 1,298
17년 전 조회 3,244
17년 전 조회 2,830
17년 전 조회 4,098
17년 전 조회 2,260
17년 전 조회 2,356
17년 전 조회 1,405
17년 전 조회 2,523
17년 전 조회 2,208
17년 전 조회 2,970
17년 전 조회 2,479
17년 전 조회 1,640
17년 전 조회 2,433
17년 전 조회 1,590
17년 전 조회 1,177
17년 전 조회 2,238
17년 전 조회 2,884
17년 전 조회 4,060
17년 전 조회 3,148
17년 전 조회 1,415
17년 전 조회 1,706
17년 전 조회 2,246
17년 전 조회 1,548
17년 전 조회 1,725
17년 전 조회 2,717
17년 전 조회 2,143
17년 전 조회 1,795
17년 전 조회 4,200
17년 전 조회 3,047
17년 전 조회 1,442
17년 전 조회 3,572
17년 전 조회 2,800
17년 전 조회 2,078
17년 전 조회 1,298
17년 전 조회 2,335
17년 전 조회 2,070
17년 전 조회 1,982
17년 전 조회 1,926
17년 전 조회 1,178
17년 전 조회 1,882
17년 전 조회 2,936
🐛 버그신고