cheditor로 올린이미지를 리스트로 뽑고싶습니다

동일질문을 어제드렸는데 천상재회님이 아래의 답변을 주셨는데요.
 
http://www.sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=3643

링크는 첫번째 이미지를 썸네일을 만듭니다.... 목록에서도 같은 방법으로 처리를 하면 나옵니다...
-------------------------------------------------------------------------
내용은 이거걸랑여 근데 까막눈인지라...
이걸 어디에 무슨파일에 어떻게 하는건지요.
사실 썸네일이고 뭐고간에 cheditor로 올린 이미지를 게시목록에 갤러리처럼
한장씩만 뽑고싶은데 도무지 초보인지라 재질문드립니다.
이제 포인트가 1800남았네여. 다 겁니다 ㅠ
---------------------------------------------------------------------------
 
위 답변의 주소내용은 이렇습니다. 
 
어찌 하다보니 만들게 되었습니다. -_-;;
여전히 짜집기입니다.
- 제약사항 - 

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>";
    }
|
댓글을 작성하시려면 로그인이 필요합니다.

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
19년 전 조회 2,017
19년 전 조회 4,001
19년 전 조회 1,600
19년 전 조회 1,548
19년 전 조회 1,924
19년 전 조회 1,628
19년 전 조회 1,627
19년 전 조회 1,570
19년 전 조회 1,507
19년 전 조회 1,786
19년 전 조회 1,353
19년 전 조회 1,585
19년 전 조회 1,585
19년 전 조회 1,622
19년 전 조회 1,591
19년 전 조회 1,531
19년 전 조회 1,554
19년 전 조회 1,531
19년 전 조회 1,517
19년 전 조회 1,741