그누보드 첨부이미지 뽑아오기 - 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개
13년 전
완전 강추합니다 !!!!!!!!!!!!
sharin
13년 전
썸네일이 리스트에 안 보여지고, noimage 이미지 경로가 썸네일 대신에 뜨네요....ㅠㅠ 어떻게 해야 할까요
13년 전
음...직접 수정한 소스를 봐야 알 수 있겠네요.
참고로 제가 카페24만 사용해서 그곳에서만 테스트를 했는데, 아직은 문제가 없었거든요.
참고로 제가 카페24만 사용해서 그곳에서만 테스트를 했는데, 아직은 문제가 없었거든요.
13년 전
강추합니다 !!!!!!!!!!!!
13년 전
ㅋㅋ 오류가 있네요. 열네번째 줄 부근의 $img[$i] = $attach_img[$i]; 를 $img[$i] = $attach_img[$k];로 수정해 주세요.
13년 전
2번 내용을 적용할려고 하는데, 파일은 알겠는데, 어디쯤에 넣어야 할지를 모르겠습니다.
<?
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++)
{
$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의 아무 곳에나 넣으면 된다는 건지....좀 가르쳐 주시면 고맙겠습니다.
13년 전
썸네일 부분을 함수화 시킨 것이기 때문에 아래처럼 간단히 코딩할 수 있다는 것입니다. 위 내용을 첨부된 함수로 대체하면 아래처럼 될 것입니다.
<?
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>"; //불당썸
}
}
?>
<?
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>"; //불당썸
}
}
?>
ivdex
12년 전
위처럼 넣으면 아예 아무것도 출력이 안되네요..
불당썸도 사용중이구요...
불당썸도 사용중이구요...
다크롭서클
13년 전
에디터 이미지 추출 방법 중에 가장 안정적인 것 같습니다. 감사합니다.^^
13년 전
감사합니다.^^
coolpan
13년 전
감사합니다~~
13년 전
와 너무 감사합니다. 굿이네요
kajama
12년 전
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); //불당썸
이걸 어디다 넣어야하는지 안가르쳐주셨네요 ;;; 에휴... 위에 댓글봐도 뭔말인지...;
12년 전
한별아빠님 덕분에 에디터 이미지 가져오기 성공했습니다. 고맙습니다.
12년 전
한페이지에 하나씩 넘길 수 있나요? 겔러리처럼^^ 어디 데모 링크없을까요?
12년 전
초보라 잘 모르겠는데...
list.skin.php 수정 된 소스를 올려 주시면 안될까요??
list.skin.php 수정 된 소스를 올려 주시면 안될까요??
1년 전
그누보드5 에도 적용되는지요?
게시글 목록
| 번호 | 제목 |
|---|---|
| 34706 | |
| 34693 | |
| 34563 | |
| 34536 | |
| 34521 | |
| 34480 | |
| 34479 | |
| 34466 | |
| 34437 | |
| 34436 | |
| 34435 | |
| 34406 | |
| 34398 | |
| 34387 | |
| 34382 | |
| 34375 | |
| 34364 | |
| 34336 | |
| 34294 | |
| 34293 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기