최신글에서 썸네일생성시 질문드립니다.
본문
위 팁을이용해서 리스트페이지에서 첨부파일 모두를 썸네일로 생성했습니다.
최신글에서도 리스트처럼 썸네일을 생성해야하는데 원본주소를 가져오지못하는지 썸네일생성이 안되네요.
원래 최신글에서 첨부파일 전체를 사용할수없는건지 궁금하네요.
thumbnail.lib에 추가한 코드입니다.
// 게시글리스트 전체 썸네일 생성
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;
$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);
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;
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'];
$srcfile = G5_PATH.$data_path;
if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {
$size = @getimagesize($srcfile);
if(empty($size))
continue;
$filename = basename($srcfile);
$filepath = dirname($srcfile);
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
$alt = get_text($malt[1]);
break;
}
}
}
if(!$filename)
return false;
$tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
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;
}
$thumb = array("src"=>$src, "ori"=>$ori, "alt"=>$alt);
return $thumb;
}
latest.skin.php 최신글 스킨에 적용한 코드입니다.
<?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);
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'] = '이미지가 없습니다.';
}
$caption = $list[$i]['subject'].' <span>['.$list[$i]['wr_content'].']</span>';
echo '<a href="'.G5_DATA_URL.'/file/'.$bo_table.'/'.$list[$i][file][$s][file].'">'.$img_content.'</a>';
}
}?>
!-->!-->
답변 1
최신글을 불러오는 페이지가 index.php 인가요?
일반적으로 thumbnail.lib.php 파일을 인클루드 하지 않거든요.
추가로 인클루드 해주셔야 합니다.
아래 소스를 index.php 에 추가해보세요.
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
답변을 작성하시기 전에 로그인 해주세요.