업로드 이미지 썸네일 생성

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,015
17년 전 조회 1,047
17년 전 조회 1,857
17년 전 조회 1,601
17년 전 조회 1,859
17년 전 조회 2,649
17년 전 조회 3,033
17년 전 조회 3,227
17년 전 조회 3,334
17년 전 조회 1,468
17년 전 조회 1,427
17년 전 조회 2,263
17년 전 조회 1,986
17년 전 조회 2,298
17년 전 조회 2,823
17년 전 조회 3,273
17년 전 조회 2,371
17년 전 조회 1,641
17년 전 조회 3,213
17년 전 조회 3,078
17년 전 조회 3,053
17년 전 조회 3,921
17년 전 조회 2,594
17년 전 조회 2,417
17년 전 조회 2,666
17년 전 조회 2,903
17년 전 조회 2,618
17년 전 조회 1,463
17년 전 조회 1,907
17년 전 조회 1,499
17년 전 조회 1,922
17년 전 조회 2,520
17년 전 조회 8,702
17년 전 조회 3,163
17년 전 조회 4,252
17년 전 조회 1,989
17년 전 조회 3,668
17년 전 조회 1,562
17년 전 조회 1,394
17년 전 조회 2,331
17년 전 조회 1,325
17년 전 조회 1,641
17년 전 조회 1,475
17년 전 조회 2,542
17년 전 조회 1,508
17년 전 조회 1,098
17년 전 조회 1,232
17년 전 조회 3,108
17년 전 조회 2,173
17년 전 조회 1,980
17년 전 조회 1,223
17년 전 조회 2,455
17년 전 조회 1,178
17년 전 조회 1,138
17년 전 조회 1,384
17년 전 조회 2,747
17년 전 조회 2,402
17년 전 조회 2,491
17년 전 조회 1,189
17년 전 조회 1,307
17년 전 조회 3,252
17년 전 조회 2,836
17년 전 조회 4,107
17년 전 조회 2,268
17년 전 조회 2,362
17년 전 조회 1,416
17년 전 조회 2,536
17년 전 조회 2,220
17년 전 조회 2,977
17년 전 조회 2,487
17년 전 조회 1,648
17년 전 조회 2,441
17년 전 조회 1,598
17년 전 조회 1,184
17년 전 조회 2,244
17년 전 조회 2,890
17년 전 조회 4,070
17년 전 조회 3,157
17년 전 조회 1,424
17년 전 조회 1,709
17년 전 조회 2,252
17년 전 조회 1,557
17년 전 조회 1,731
17년 전 조회 2,726
17년 전 조회 2,152
17년 전 조회 1,803
17년 전 조회 4,208
17년 전 조회 3,056
17년 전 조회 1,448
17년 전 조회 3,576
17년 전 조회 2,808
17년 전 조회 2,087
17년 전 조회 1,306
17년 전 조회 2,346
17년 전 조회 2,078
17년 전 조회 1,992
17년 전 조회 1,938
17년 전 조회 1,187
17년 전 조회 1,891
17년 전 조회 2,945
🐛 버그신고