테스트 사이트 - 개발 중인 베타 버전입니다

최신글에서 썸네일생성시 질문드립니다. 채택완료

D2Bweb 7년 전 조회 2,460

https://sir.kr/g5_tip/2410

 

위 팁을이용해서 리스트페이지에서 첨부파일 모두를 썸네일로 생성했습니다.

최신글에서도 리스트처럼 썸네일을 생성해야하는데 원본주소를 가져오지못하는지 썸네일생성이 안되네요.

원래 최신글에서 첨부파일 전체를 사용할수없는건지 궁금하네요.

 

thumbnail.lib에 추가한 코드입니다.

</p>

<p>// 게시글리스트 전체 썸네일 생성

function get_each_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_create=false, $is_crop=false, $crop_mode='center', $is_sharpen=false, $um_value='80/0.5/3', $option=0)

{

    global $g5, $config;

    $filename = $alt = "";

    $edt = false;</p>

<p>    $sql = " select bf_file, bf_content from {$g5['board_file_table']} 

                where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_type between '1' and '3' order by bf_no limit $option, 1 ";

    $row = sql_fetch($sql);</p>

<p>    if($row['bf_file']) {

        $filename = $row['bf_file'];

        $filepath = G5_DATA_PATH.'/file/'.$bo_table;

        $alt = get_text($row['bf_content']);

    } else {

        $write_table = $g5['write_prefix'].$bo_table;

        $sql = " select wr_content from $write_table where wr_id = '$wr_id' ";

        $write = sql_fetch($sql);

        $matches = get_editor_image($write['wr_content'], false);

        $edt = true;</p>

<p>        for($i=0; $i<count($matches[1]); $i++)

        {

            // 이미지 path 구함

            $p = parse_url($matches[1][$i]);

            if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)

                $data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);

            else

                $data_path = $p['path'];</p>

<p>            $srcfile = G5_PATH.$data_path;</p>

<p>            if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {

                $size = @getimagesize($srcfile);

                if(empty($size))

                    continue;</p>

<p>                $filename = basename($srcfile);

                $filepath = dirname($srcfile);</p>

<p>                preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);

                $alt = get_text($malt[1]);</p>

<p>                break;

            }

        }

    }</p>

<p>    if(!$filename)

        return false;</p>

<p>    $tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);</p>

<p>    if($tname) {

        if($edt) {

            // 오리지날 이미지

            $ori = G5_URL.$data_path;

            // 썸네일 이미지

            $src = G5_URL.str_replace($filename, $tname, $data_path);

        } else {

            $ori = G5_DATA_URL.'/file/'.$bo_table.'/'.$filename;

            $src = G5_DATA_URL.'/file/'.$bo_table.'/'.$tname;

        }

    } else {

        return false;

    }</p>

<p>    $thumb = array("src"=>$src, "ori"=>$ori, "alt"=>$alt);</p>

<p>    return $thumb;

}</p>

<p>

 

latest.skin.php 최신글 스킨에 적용한 코드입니다.

</p>

<p><?php for ($s=1; $s<count($list[$i][file]); $s++) { // 첨부파일전체를 썸네일로 생성

                            if($s==count($list[$i][file])-1) {

                                break;

                            } else {

                                $thumb = get_each_thumbnail($board, $list[$i]['wr_id'], $thumb_small_width, $thumb_small_height, false, true, 'center', false, '80/0.5/3', $s); </p>

<p>                                if($thumb['src']) {

                                    $img = $thumb['src'];

                                    $img_content = '<img src="'.$img.'" class="lt_img">';

                                } else {

                                    $img_content = '<img src="'.G5_THEME_URL.'/resource/image/no_image.png" style="width:100%;height:auto;border:1px solid #e9e9e9;">';

                                    $thumb['alt'] = '이미지가 없습니다.';

                                }</p>

<p>                                $caption = $list[$i]['subject'].'  <span>['.$list[$i]['wr_content'].']</span>';</p>

<p>                                echo '<a href="'.G5_DATA_URL.'/file/'.$bo_table.'/'.$list[$i][file][$s][file].'">'.$img_content.'</a>';

                            }

                        }?></p>

<p>

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

e
7년 전

최신글을 불러오는 페이지가 index.php 인가요?

일반적으로 thumbnail.lib.php 파일을 인클루드 하지 않거든요.

추가로 인클루드 해주셔야 합니다.

아래 소스를 index.php 에 추가해보세요.

include_once(G5_LIB_PATH.'/thumbnail.lib.php');

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

D
D2Bweb
7년 전
thumbnail.lib.php는 최신글 스킨에서 인클루드해둔상태라 썸네일 생성에는 문제가없습니다. 문제는 첨부파일 1번은 썸네일 생성이 잘 되는데 2번부터는 원본주소를 못 불러오는듯하네요..;;

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인