cheditor의 업로드 기능을 이용한 첨부이미지를썸네일로 생성 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

cheditor의 업로드 기능을 이용한 첨부이미지를썸네일로 생성 정보

cheditor의 업로드 기능을 이용한 첨부이미지를썸네일로 생성

본문

어찌 하다보니 만들게 되었습니다. -_-;;
여전히 짜집기입니다.
- 제약사항 -

1. 그누보드는 루트 폴더 바로 아래 설치되어 있어야 됩니다.
예 : http://myhome.com/gnu

2. cheditor를 이용한 위지웍에디트 모드에서 cheditor에 자체 내장된 이미지 업로드기능을 이용한
이미지에만 적용됩니다.

3. 첫번째 이미지는 반드시 cheditor로 올린것이어야 됩니다.
4. 첫번째 이미지만 썸네일로 생성됩니다.

wr_content에서 img 테그에서 순서대로 파일을 뽑아오기 때문에
첫부분에 다른 서버에 파일을 링크하면 안됩니다.


/**  썸네일 함수
$file : 원본이미지 파일
$save_filename : 저장할 파일명
$save_path : 저장할 경로
$max_width : 만들이미지의 width 값
$max_height : 만들이미지의 height 값
*/
function thumimg($file, $save_filename, $save_path, $max_width, $max_height)
{
      $img_info = getImageSize($file);
      if($img_info[2] == 1)
      {
              $src_img = ImageCreateFromGif($file);
              }elseif($img_info[2] == 2){
              $src_img = ImageCreateFromJPEG($file);
              }elseif($img_info[2] == 3){
              $src_img = ImageCreateFromPNG($file);
              }else{
              return 0;
      }
      $img_width = $img_info[0];
      $img_height = $img_info[1];

      if($img_width > $max_width || $img_height > $max_height)
      {
              if($img_width == $img_height)
              {
                    $dst_width = $max_width;
                    $dst_height = $max_height;
              }elseif($img_width > $img_height){
                    $dst_width = $max_width;
$dst_height = $max_height;
//                    $dst_height = ceil(($max_width / $img_width) * $img_height);
              }else{
                    $dst_height = $max_height;
$dst_height = $max_height;
//                    $dst_width = ceil(($max_height / $img_height) * $img_width);
              }
      }else{
              $dst_width = $img_width;
              $dst_height = $img_height;
      }
      if($dst_width < $max_width) $srcx = ceil(($max_width - $dst_width)/2); else $srcx = 0;
      if($dst_height < $max_height) $srcy = ceil(($max_height - $dst_height)/2); else $srcy = 0;

      if($img_info[2] == 1)
      {
              $dst_img = imagecreate($max_width, $max_height);
      }else{
              $dst_img = imagecreatetruecolor($max_width, $max_height);
      }

      $bgc = ImageColorAllocate($dst_img, 255, 255, 255);
      ImageFilledRectangle($dst_img, 0, 0, $max_width, $max_height, $bgc);
      ImageCopyResampled($dst_img, $src_img, $srcx, $srcy, 0, 0, $dst_width, $dst_height, ImageSX($src_img),ImageSY($src_img));

      if($img_info[2] == 1)
      {
              ImageInterlace($dst_img);
              ImageGif($dst_img, $save_path.$save_filename);
      }elseif($img_info[2] == 2){
              ImageInterlace($dst_img);
              ImageJPEG($dst_img, $save_path.$save_filename);
      }elseif($img_info[2] == 3){
              ImagePNG($dst_img, $save_path.$save_filename);
      }
      ImageDestroy($dst_img);
      ImageDestroy($src_img);
}
// 썸네일 함수끝
function extract_img($src) { 
$re = '/src[ =]+[\'"]([^\'"]+\.(?:gif|jpg|png|bmp))[\'"]/i'; 
preg_match_all($re, $src, &$match, PREG_PATTERN_ORDER); 
return $match[1];
}
// 아래 g4_write_에 게시판 id를 입력해주세요
//예) g4_write_gallery

$sql="select * from g4_write_게시판ID입력 order by wr_datetime DESC limit 4";
$result=mysql_query($sql);
for($i=0; $data=mysql_fetch_array($result); $i++){
$imgs[$i] = extract_img($data[wr_content]);
}

$total = count($imgs);

for($i=0 ; $total>$i; $i++){
$fullpath = explode("/", $imgs[$i][0]);
$url = "http://".$fullpath[2]."/".$fullpath[3];
$ch_img = str_replace("$url","", $imgs[$i][0]);
$file=$g4[path].$ch_img;
$filename=count($fullpath) - 1;
$save_filename = $fullpath[$filename].".thum";
$save_path =str_replace("$fullpath[$filename]","",$file);
$max_width ="80";
$max_height ="60";
//echo $file."->대상파일<BR>";
//echo $save_filename."->저장될파일명<BR>";
//echo $save_path."->저장될경로명<BR>";

if(!file_exists($save_filename)){
thumimg($file, $save_filename, $save_path, $max_width, $max_height);
}
echo "<img src='$file.thum'><br>";
}
추천
1

댓글 6개

전체 3,313 |RSS
그누4 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT