에디터로 올린 이미지를 먼저 썸네일로만들고 싶습니다.
본문
아래에 긴 코드가 있는데 궁금한것이 있습니다.
1. $write['img_rows'] 가 무엇을 찾는것인지 궁금합니다. echo $rows; 로 하면 값이 1이 나오긴하는데... 그 값 1이 무엇을 의미하는지 모르겠네요...
$rows = (isset($write['img_rows']) && $write['img_rows'] > 1) ? $write['img_rows'] : 1;
2. 첨부파일에 이미지가 있으면 우선 썸네일을 생성하는데 어느 부분을 수정해야 에디터로 올린 이미지를 먼저 썸네일로 수정할 수 있을까요...
긴 코드를 적어놔 죄송합니다.
// 게시물 썸네일 생성
function apms_wr_thumbnail($bo_table, $write, $thumb_width, $thumb_height, $is_create=false, $is_crop=false, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3') {
global $g5, $config;
$img = array();
$limg = array();
$lalt = array();
$link = array();
$thumb = array();
$no_thumb = array('is_thumb'=>false, 'src'=>'', 'alt'=>'', 'org'=>'', 'height'=>'');
$chk_img = (isset($write['chk_img']) && $write['chk_img']) ? true : false; // Check Image
$rows = (isset($write['img_rows']) && $write['img_rows'] > 1) ? $write['img_rows'] : 1;
echo $write['img_rows'];
// 비밀글 & 블라인드글
if (strstr($write['wr_option'], 'secret') || $write['as_shingo'] < 0) {
if($chk_img) return 0;
if($rows > 1) {
$thumb[0] = $no_thumb;
} else {
$thumb = $no_thumb;
}
return $thumb;
}
$is_thumb = (!$chk_img && isset($write['as_thumb']) && $write['as_thumb'] && $rows == "1") ? true : false;
$is_thumb_no = (isset($write['is_thumb_no']) && $write['is_thumb_no']) ? true : false;
$no_img = (isset($write['no_img']) && $write['no_img']) ? $write['no_img'] : '';
$make_thumb = true;
if($is_thumb && isset($write['as_thumb']) && $write['as_thumb'] == '1') {
$z = 0;
$make_thumb = false;
unset($write);
} else if($is_thumb) {
$tmp_thumb = apms_video_thumbnail($write['as_thumb'], 1);
if($tmp_thumb) {
$z = 1;
$img[0]['img'] = $tmp_thumb;
$img[0]['alt'] = '';
$make_thumb = false;
unset($write);
}
}
if($make_thumb) {
$wr_id = $write['wr_id'];
$wr_content = $write['wr_content'];
// 링크
for ($i=1; $i<=G5_LINK_COUNT; $i++) {
$link[$i] = get_text($write["wr_link{$i}"]);
}
unset($write);
$result = sql_query(" 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", false);
$z = 0;
for ($i=0; $row=sql_fetch_array($result); $i++) {
if($row['bf_file']) {
$img[$z]['alt'] = get_text($row['bf_content']);
$img[$z]['img'] = G5_DATA_URL.'/file/'.$bo_table.'/'.$row['bf_file'];
$z++;
if($z == $rows) break;
}
}
if($z != $rows) {
if(!$wr_content) {
$write_table = $g5['write_prefix'].$bo_table;
$sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
$write = sql_fetch($sql);
$wr_content = $write['wr_content'];
}
$matches = get_editor_image($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(is_file($srcfile)) {
$size = @getimagesize($srcfile);
if(empty($size)) {
continue;
}
$img[$z]['img'] = $matches[1][$i];
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
$img[$z]['alt'] = get_text($malt[1]);
$z++;
if($z == $rows) break;
} else {
$limg[] = $matches[1][$i];
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
$lalt[] = get_text($malt[1]);
}
}
}
if($z != $rows) { // 링크동영상 체크
for ($i=1; $i <= count($link); $i++) {
$video = apms_video_info($link[$i]);
if(!$video['type']) continue;
$srcfile = apms_video_img($video['video_url'], $video['vid'], $video['type'], $video['img']);
if(!$srcfile || $srcfile == 'none') continue;
$size = @getimagesize($srcfile);
if(empty($size)) {
continue;
}
$img[$z]['img'] = str_replace(G5_PATH, G5_URL, $srcfile);
$z++;
if($z == $rows) break;
}
}
if($z != $rows) { //본문동영상 이미지 체크
if(preg_match_all("/{(동영상|video)\:([^}]*)}/is", $wr_content, $match)) {
$match_cnt = count($match[2]);
for ($i=0; $i < $match_cnt; $i++) {
$video = apms_video_info(trim(strip_tags($match[2][$i])));
if(!$video['type']) continue;
$srcfile = apms_video_img($video['video_url'], $video['vid'], $video['type'], $video['img']);
if(!$srcfile || $srcfile == 'none') continue;
$size = @getimagesize($srcfile);
if(empty($size)) {
continue;
}
$img[$z]['img'] = str_replace(G5_PATH, G5_URL, $srcfile);
$z++;
if($z == $rows) break;
}
}
}
if($z != $rows) { //링크 이미지
for($i=0; $i < count($limg); $i++) {
$img[$z]['img'] = $limg[$i];
$img[$z]['alt'] = $lalt[$i];
$z++;
if($z == $rows) break;
}
}
}
// Check Image
if($chk_img) {
$chk_img = (isset($img[0]['img']) && $img[0]['img']) ? $img[0]['img'] : 0;
return $chk_img;
}
if($z == 0) {
if($no_img) {
$img[$z]['org'] = $no_img;
$img[$z]['img'] = $no_img;
$img[$z]['alt'] = '';
} else {
if($rows > 1) {
$thumb[0] = $no_thumb;
} else {
$thumb = $no_thumb;
}
return $thumb;
}
}
// 썸네일
$tmp = array();
$j = 0;
for($i = 0; $i < count($img); $i++) {
if($thumb_width > 0 && !$is_thumb_no) {
$tmpimg = apms_thumbnail($img[$i]['img'], $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
if(!$tmpimg['src']) continue;
$tmp[$j]['is_thumb'] = $tmpimg['is_thumb'];
$tmp[$j]['src'] = $tmpimg['src'];
$tmp[$j]['height'] = $tmpimg['height'];
} else {
$tmp[$j]['is_thumb'] = false;
$tmp[$j]['src'] = $img[$i]['img'];
$tmp[$j]['height'] = '';
}
$tmp[$j]['org'] = $img[$i]['img'];
$tmp[$j]['alt'] = $img[$i]['alt'];
$j++;
}
if($j == 0) {
if($rows > 1) {
$thumb[0] = $no_thumb;
} else {
$thumb = $no_thumb;
}
} else {
$thumb = ($rows > 1) ? $tmp : $tmp[0];
}
return $thumb;
}
답변 1
1. $write['img_rows']는 추출할 이미지의 갯수를 의미합니다.
2. 아래와 같이 소스의 위치를 바꾸면 됩니다.
$z = 0;
if(!$wr_content) {
$write_table = $g5['write_prefix'].$bo_table;
$sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
$write = sql_fetch($sql);
$wr_content = $write['wr_content'];
}
$matches = get_editor_image($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(is_file($srcfile)) {
$size = @getimagesize($srcfile);
if(empty($size)) {
continue;
}
$img[$z]['img'] = $matches[1][$i];
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
$img[$z]['alt'] = get_text($malt[1]);
$z++;
if($z == $rows) break;
} else {
$limg[] = $matches[1][$i];
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
$lalt[] = get_text($malt[1]);
}
}
if($z != $rows) {
$result = sql_query(" 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", false);
for ($i=0; $row=sql_fetch_array($result); $i++) {
if($row['bf_file']) {
$img[$z]['alt'] = get_text($row['bf_content']);
$img[$z]['img'] = G5_DATA_URL.'/file/'.$bo_table.'/'.$row['bf_file'];
$z++;
if($z == $rows) break;
}
}
}
!-->
답변을 작성하시기 전에 로그인 해주세요.