포인트가 얼마 없지만... 썸네일 생성 방법좀... > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

포인트가 얼마 없지만... 썸네일 생성 방법좀... 정보

포인트가 얼마 없지만... 썸네일 생성 방법좀...

본문

 
도와주세요...
 
기존 http://www.sir.co.kr/bbs/tb.php/g4_skin/22233 벼룩시장 스킨을 어설프게
짜집기하여
http://www.biketip.co.kr 메인에 보이는 최신글에 적용을 하였는데,
썸네일 기능이 없어 로딩이 무지 느리네요.
 
위 스킨에서 썸네일 적용시켜서 최신글로 뽑아 낼 수 있을까요 ?
 
고수님들 부탁드립니다. (--)(__)(--)
 
쥐꼬리밖에 없는 포인트 다 겁니다 ㅜㅜ

댓글 전체

게시판 소스를 건드리지 않고 최신글 스킨만으로 썸네일을 생성시켜 적용 시킬 수 있는 것인가요?

그렇다면 아래는 제가 사용하는 최신글 소스인데 어떻게 바꾸면 될까요 ? ㅜㅜ

<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

$cols  = 8; //  이미지 가로갯수 //  이미지 세로 갯수는 메인에서 지정(총 이미지 수)
$image_h  = 5; // 이미지 상하 간격

$col_width = (int)(99 / $cols);

$data_path = $g4[path]."/data/file/$bo_table";

?>
<style type="text/css">
<!--
.data  { font-family:돋움; font-size:8pt; color:#999999; }
-->
</style>

<table width="100%" border="0" align=right cellspacing="0" cellpadding="0">
<tr><td height='25' background='<?=$latest_skin_path?>/img/la_titie.gif' style='padding-top:2px; padding-left:40px;'><a href='<?=$g4[bbs_path]?>/board.php?bo_table=<?=$bo_table?>' onfocus='this.blur()'><strong><?=$board[bo_subject]?></strong></a></td></tr>
<tr><td height='2'></td></tr>
<tr>
<td align='center'>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>

<? for ($i=0; $i<count($list); $i++) {
  if ($i>0 && $i%$cols==0) { echo "</tr><tr><td colspan='$cols' height='$image_h'></td></tr><tr>"; }
?>
<?
$ex6_filed = explode("|",$list[$i][wr_6]);
$ext6_00  = $ex6_filed[0];
$ext6_01  = $ex6_filed[1];
$ext6_02  = $ex6_filed[2];
$ext6_03  = $ex6_filed[3];
$ext6_04  = $ex6_filed[4];
$ext6_05  = $ex6_filed[5];
$ext6_06  = $ex6_filed[6];
$ext6_07  = $ex6_filed[7];
$ext6_08  = $ex6_filed[8];

$ex8_filed = explode("|",$list[$i][wr_8]);
$ext8_00  = $ex8_filed[0];
$ext8_01  = $ex8_filed[1];

?>


<td width="<?=$col_width?>%" align="center" valign='top'>

<?
$image = $list[$i][file][0][file]; //원본
$img=$data_path. "/".$image;  //썸네일이 없을경우 원본출력
$thumb = $thumb_path. "/". $list[$i][wr_id];

  if ( file_exists($thumb) )
$img = $thumb;
 
    $style = "font-family:돋움; font-size:9pt; color:#636363;";
    if ($list[$i][icon_new])
    $style = "style='font-family:돋움; font-size:9pt; color:#006F00;' ";
$subject = "<span $style>".cut_str($list[$i][subject],10)."</span>"; //제목 글자수 자르기

//    if ($list[$i]['comment_cnt']) //코
//        $cmt = "({$list[$i]['comment_cnt']})";

$bg = "";  //새글?
    if ($list[$i][icon_new])
        $bg="la_top_2.gif";
    else
        $bg="la_top_1.gif";

    echo $list[$i][icon_reply] . " ";

echo "<table align='center' border=1 cellpadding=0 cellspacing=0 width=96 bordercolor='#E8E7E7' bordercolordark='white' bordercolorlight='#E8E7E7'>";
echo "<tr> <td width='100%' align='center'>";
echo "<table width='100%' cellpadding='1' cellspacing='0' border='0'>";
echo " <tr><td height='18' align=center valign=bottom class='data'><a href='{$list[$i][href]}' onfocus='this.blur()'>{$ext6_04}</td></tr>";
echo " <tr><td valign='top' align='center'><a href='{$list[$i][href]}' onfocus='this.blur()'><img src='$img' width='85' height='55' border=1></a></td></tr>";
echo " <tr><td height='18' align=center valign=bottom class='data'>{$ext8_00}만원/{$ext6_02}년</td></tr></table>";
        echo "</td></tr>";
echo "</table>";



?>
</td>
<? } ?>

<?
$cnt = ($i%$cols);
for ($k=$cnt; $k<$cols && $cnt; $k++) {
    echo "<td width=$col_width%>&nbsp;</td>";
}
?>

  <? if (count($list) == 0) { echo "<td height=80 align=center>게시물이 없습니다.</td>"; } ?>
  </tr>
</table></td>
</tr>
</table>

<script language="javascript">
function popupImage(imageURL){
imageHandle=open("","popupForImage","toolbar=no,location=no,status=no,manubar=no,scrollbars=no,resizable=no,width=100,height=100,top=0,left=0");
  imageHandle.document.write("<title>  </title>");
  imageHandle.document.write("<style>");
  imageHandle.document.write("*{margin:0;padding:0;border:0;}");
  imageHandle.document.write("</style>");
  imageHandle.document.write("<img src=\""+imageURL+"\" onload=\"window.resizeTo(this.width+6,this.height+55);\" onclick=\"self.close();\" style=\"cursor:hand;\" title=\"클릭하면 닫힙니다.\">");
}
</script>
스킨 자료실에 보면 섬네일생성소스가 장착된 최신글 스킨이 많이 있습니다..
그 스킨들을 참고하셔서 섬네일생성소스를 추가하시면 되겠네요...^^
우선 제가 사용하는 방법을 올리겠습니다.
본 소스는(phpschool의 어떤분의 섬네일 관련 소스를 참고해 약간 수정했습니다.)

1. 저같은 경우 저기 아래 섬네일 함수를 이미 제가 자주 사용하는 함수목록에 등록시켰으며, 그 함수를 인쿨루드 시켜 옮니다.

2. 섬네일을 만들고 싶은 파일에서 섬네일을 만들 이미지의 실제위치를 알아 둡니다.
저는 $file 이라는 변수에 파일경로 를 담아 두었습니다.

3. 섬네일을 함수를 호출합니다. 리턴값은 섬네일 위치를 돌려줍니다.즉 그 섬네일 리턴값을 바로 img태그 src에 넣으면 됩니다.^^
$thumb_img = create_thumbnail2($file,"$g4[path]/data/file/thumb",_indexbasic,$width)
설명 : create_thumbnail2(파일경로,"$g4[path]/data/file/thumb",섬네일이름,픽셀사이즈)

4. 여기 아래 섬네일을 만드는 함수를 적정한 위치에 등록 해두고 인쿨루드 시켜 오셔서 사용하세요
//지정된 디렉토리에 섬네일을 만든다.
//파일경로,저장디렉토리,생성될섬네일파일이름,크기,고정방법
function create_thumbnail2($file, $dist, $where_used ,$max_side = false, $fixed = false) {

// 1 = GIF, 2 = JPEG
if(!$max_side) $max_side = 100;

if(file_exists($file)) {
$type = getimagesize($file);

if(!function_exists('imagegif') && $type[2] == 1) {
$error = 'Filetype not supported. Thumbnail not created.';
}elseif (!function_exists('imagejpeg') && $type[2] == 2){
$error = 'Filetype not supported. Thumbnail not created.';
}else{
// create the initial copy from the original file
if($type[2] == 1) {
$image = imagecreatefromgif($file);
}
elseif($type[2] == 2) {
$image = imagecreatefromjpeg($file);
}

if(function_exists('imageantialias'))
imageantialias($image, TRUE);

$image_attr = getimagesize($file);
// figure out the longest side

if($image_attr[0] > $image_attr[1]) {
$image_width = $image_attr[0];
$image_height = $image_attr[1];

if($fixed) {
$image_new_width  = $max_side;
$image_new_height = (int)($max_side * 3 / 4);
// 4:3 ratio
} else {
$image_new_width = $max_side;

$image_ratio = $image_width / $image_new_width;
$image_new_height = (int) ($image_height / $image_ratio);
}
}else{ //width > height
$image_width = $image_attr[0];
$image_height = $image_attr[1];
if($fixed) {
$image_new_height = $max_side;
$image_new_width  = (int)($max_side * 3 / 4);
// 3:4 ratio
} else {
$image_new_height = $max_side;

$image_ratio = $image_height / $image_new_height;
$image_new_width = (int) ($image_width / $image_ratio);
}//height > width
}//end if/else

$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
@imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);

@mkdir($dist, 0707);
@chmod($dist, 0707);

$thumb = preg_replace('!(\.[^.]+)?$!', '.thumbnail'.$where_used.'$1', basename($file), 1);
$thumbpath = $dist."/".$thumb;
//$thumbpath = str_replace(basename($file), $thumb, $file);

// move the thumbnail to it's final destination
if($type[2] == 1) {
if (!imagegif($thumbnail, $thumbpath)) {
$error = 'Thumbnail path invalid';
}
}
elseif($type[2] == 2) {
if (!imagejpeg($thumbnail, $thumbpath)) {
$error = 'Thumbnail path invalid';
}
}
}
}else{ //end file_exists($file)
$error = 'File not found';
}

if(!empty($error)) {
die($error);
}else{
return $thumbpath;
}
}//function
<?if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
다음 라인에
$img_width = 85; //썸네일 가로길이
$img_height = 55; //썸네일 세로길이
$img_quality = 60; //퀼리티 100이하로 설정

if (!function_exists("imagecopyresampled")) alert("GD 2.0.1 이상 버전이 설치되어 있어야 사용할 수 있는 스킨 입니다.");

$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';

@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
추가하시고

$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]);
            imagepng($dst, $thumb_path.'/'.$list[$i][wr_id], $img_quality);
            chmod($thumb_path.'/'.$list[$i][wr_id], 0606);
        }
    }
추가하시면 될것같네요..
전체 66,554 |RSS
그누4 질문답변 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT