그누보드 첨부이미지 뽑아오기 - function
갤러리 등에서 썸네일 이미지로 사용하기 위해 첨부된 이미지 주소를 불러오는 코드를 함수화시킨 것입니다. 직접 파일첨부 올린 이미지 뿐만 아니라 에디트에서 첨부된 이미지도 찾아서 뽑아 주며, 뽑아올 이미지 갯수도 지정할 수 있습니다. 단, 글내용에 링크로 넣은 이미지는 뽑아 올 수 없습니다.
1. 아래 함수를 그누보드의 있는 extend 폴더에 넣어 주세요.(첨부 참고)
//------------------------------------------------------------------------------------------------
// 첨부된 이미지 주소 불러오기..
function amina_attach_img($attach, $wr_content, $rows='1') {
global $g4;
function amina_attach_img($attach, $wr_content, $rows='1') {
global $g4;
$i = 0;
for ($k=0; $k<count($attach); $k++) { //직접 첨부한 이미지
if ($attach[$k][view]) {
$attach_img[$k] = $attach[$k][path]."/".$attach[$k][file];
if(preg_match("/\.(jp[e]?g|gif|png)$/i", $attach_img[$k]) && file_exists($attach_img[$k])) {
$img[$i] = $attach_img[$i];
$i++;
if($i == $rows) break;
}
}
}
for ($k=0; $k<count($attach); $k++) { //직접 첨부한 이미지
if ($attach[$k][view]) {
$attach_img[$k] = $attach[$k][path]."/".$attach[$k][file];
if(preg_match("/\.(jp[e]?g|gif|png)$/i", $attach_img[$k]) && file_exists($attach_img[$k])) {
$img[$i] = $attach_img[$i];
$i++;
if($i == $rows) break;
}
}
}
if($i != $rows) { //에디터에 삽입된 이미지
$ym = 'data/cheditor4/[^<>]*/[^<>]*\.(gif|jpg|png)';
if(preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", $wr_content, $match)) {
for ($k=0; $k<count($match[0]); $k++) {
if(eregi($ym, $match[0][$k], $tmp_img)) {
$chk_img[$i] = $g4[path]."/".$tmp_img[0];
if(file_exists($chk_img[$i])) $img[$i] = $chk_img[$i];
$ym = 'data/cheditor4/[^<>]*/[^<>]*\.(gif|jpg|png)';
if(preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", $wr_content, $match)) {
for ($k=0; $k<count($match[0]); $k++) {
if(eregi($ym, $match[0][$k], $tmp_img)) {
$chk_img[$i] = $g4[path]."/".$tmp_img[0];
if(file_exists($chk_img[$i])) $img[$i] = $chk_img[$i];
$i++;
if($i == $rows) break;
}
}
}
}
if($i == $rows) break;
}
}
}
}
return $img;
}
//----------------------------------------------------------------------------------------------
}
//----------------------------------------------------------------------------------------------
2. 게시판(board) 스킨의 list.skin.php 파일이나 최근 게시물(latest)의 latest.skin.php에 아래와 같이 적용해 주시면 됩니다. 참고로 저는 불당썸과 같이 사용합니다.
1) 한개만 뽑아 올 경우
list($list[$i][img]) = amina_attach_img($list[$i][file], $list[$i][wr_content], 1);
if(!$list[$i][img]) $list[$i][img] = $board_skin_path."/img/noimage.gif";
$list[$i][img] = thumbnail($list[$i][img],$img_width,$img_height,false,1,90); //불당썸
if(!$list[$i][img]) $list[$i][img] = $board_skin_path."/img/noimage.gif";
$list[$i][img] = thumbnail($list[$i][img],$img_width,$img_height,false,1,90); //불당썸
2) 두 개 이상 뽑아 올 경우
$list[$i][img] = amina_attach_img($list[$i][file], $list[$i][wr_content], "최대 뽑아올 이미지 갯수");
for($z=0; $z < count($list[$i][img]);$z++) {
for($z=0; $z < count($list[$i][img]);$z++) {
$list[$i][img][$z] = thumbnail($list[$i][img][$z],$img_width,$img_height,false,1,90); //불당썸
}
}
하나던 두 개 이상이던 뽑은 이미지 주소가 배열로 넘어오기 때문에 이에 대한 처리를 해 주시면 됩니다.
첨부파일
|
댓글을 작성하시려면 로그인이 필요합니다.
로그인
댓글 17개
참고로 제가 카페24만 사용해서 그곳에서만 테스트를 했는데, 아직은 문제가 없었거든요.
<?
for ($i=0; $i<count($list); $i++)
{
$img = "<img src='$board_skin_path/img/noimage.gif' border=0 title='이미지 없음'>";
$thumb = $thumb_path.'/'.$list[$i][wr_id];
// 썸네일 이미지가 존재하지 않는다면
if (!file_exists($thumb)) {
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
// 업로드된 파일이 이미지라면
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file)) {
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
break;
$rate = $img_width / $size[0];
$height = (int)($size[1] * $rate);
// 계산된 썸네일 이미지의 높이가 설정된 이미지의 높이보다 작다면
if ($height < $img_height)
// 계산된 이미지 높이로 복사본 이미지 생성
$dst = imagecreatetruecolor($img_width, $height);
else
// 설정된 이미지 높이로 복사본 이미지 생성
$dst = imagecreatetruecolor($img_width, $img_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $img_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][wr_id], $img_quality);
chmod($thumb_path.'/'.$list[$i][wr_id], 0606);
}
}
if (file_exists($thumb))
$img = "<img src='$thumb' border=0>";
else
if(preg_match("/\.(swf|wma|asf)$/i","$file") && file_exists($file))
{ $img = "<script>doc_write(flash_movie('$file', 'flash$i', '$img_width', '$img_height', 'transparent'));</script>"; }
?>
이 내용중에 포함 시켜야 하는 건지...
아니면 list.skin.php 파일이나 최근 게시물(latest)의 latest.skin.php의 아무 곳에나 넣으면 된다는 건지....좀 가르쳐 주시면 고맙겠습니다.
<?
for ($i=0; $i<count($list); $i++) {
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if(preg_match("/\.(swf|wma|asf)$/i","$file") && file_exists($file)) {
$img = "<script>doc_write(flash_movie('$file', 'flash$i', '$img_width', '$img_height', 'transparent'));</script>";
} else {
list($list[$i][img]) = amina_attach_img($list[$i][file], $list[$i][wr_content], 1);
if(!$list[$i][img]) $list[$i][img] = $board_skin_path."/img/noimage.gif";
$img = "<img src='".thumbnail($list[$i][img],$img_width,$img_height,false,1,90)."' width='{$img_width}' height='{$img_height}' border=0>"; //불당썸
}
}
?>
불당썸도 사용중이구요...
if(!$list[$i][img]) $list[$i][img] = $board_skin_path."/img/noimage.gif";
$list[$i][img] = thumbnail($list[$i][img],$img_width,$img_height,false,1,90); //불당썸
이걸 어디다 넣어야하는지 안가르쳐주셨네요 ;;; 에휴... 위에 댓글봐도 뭔말인지...;
list.skin.php 수정 된 소스를 올려 주시면 안될까요??