최신글에서 이미지 불러올때 가로/세로 크기를 구하는 방법? > 그누4 질문답변

그누4 질문답변

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

최신글에서 이미지 불러올때 가로/세로 크기를 구하는 방법? 정보

최신글에서 이미지 불러올때 가로/세로 크기를 구하는 방법?

본문

최신글에서  게시판의 '첫번째'이미지를 가져오는 코드입니다 (아래...간단하게 요약)




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

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>

<? for ($i=0; $i<count($list); $i++) { ?>

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

<?
$source_img= $list[$i][file][0][file]; // 이미지 새창 띄울때 사용
$source_img_url = "$g4[path]/data/file/$bo_table/".urlencode($list[$i][file][0][file]);
$no_img = "$latest_skin_path/img/no_image.gif"; // 첫번째 이미지가 없는경우

    /* --- 이미지 / no이미지 출력 -- *// ----------- 원본 가로크기/세로크기 구하는법????
    if (file_exists($source_img)) {
    $img = "<img src='$source_img' border='0'>";
}else{
    $img = "<img src='$no_img' border=0'>";
}


echo "<a href='{$list[$i][href]}'>". $img ."</a>";
?>

</td>
<? } ?>

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




-------------------------------------------------

현재 의도하고 작업하고자 하는 내용은... 최신글로 '첫번째이미지'를 불러올때, ....
해당이미지의 '가로크기' 가  100px을 넘어가면 게시판에서 생성된 원본이미지의 썸네일을 불러오고
'가로크기'가 100px 보다 작으면 원본이미지 자체를 임의의 지정된 가로/세로 값으로 강제로 줄여서
표시하도록 하려고 합니다.



질문의 요지는....
최신글에서 '게시판의 첫번째'이미지를 가져올때, 해당원본이미지의 크기를
어떻게하면 알수 있는지가 궁금합니다.


게시판 첫번째 원본이미지의 가로/세로 사이즈를 모르는상황에서
최신글에서 불러온다고 했을때 임의의 강제 가로/세로 값을 변수로 정하여
최신글에서 노출하기 이전에  이미지의 실제 가로사이즈를 우선 알아서
100px 이라는 값을 기준으로 각각의 다른 이미지를 표시하고자 하는데....

위 코드에서 불러오는 첫번째 이미지의 사이즈(가로크기 or 세로크기)를 알려주는 코드를
넣어서 비교하려면 어떻게 구문을 만들어야 하는지요??

댓글 전체

감사합니다. 덕분에 해결이 된듯합니다.

질문을 드린 최신글의 원래 코드는 아래와 같습니다

현재 알려주신팁을 응용해서 아래처럼 추가 해보니 잘 되는거 같은데...
혹, 틀린부분이나 좀더 나은 코드가 있으면 지적 부탁드립니다.
(이글 보시는 다른 분들께도 추가로 조언을 구합니다)



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

/* -----------------------------------------------------
★★ 썸네일&일반이미지 불러오기 최신글
---- 썸네일이미지가 없으면 원본이미지를 축소해서 가져옴
------------------------------------------------------ */

$cols  = 3;      // 이미지 가로갯수 (출력 이미지 총개수는 최신글에서 ...)
$image_h  = 10;  // 이미지 상하 간격

$thu_width = 100;  // 가로size(px)
$thu_height = 70;  // 세로size(px)
$thu_quality = 98; // 이미지의 압축률 (100 이하)

$col_width  = (int)(99 / $cols);
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb'; // 최신글 썸네일 폴더
?>

<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='1'></td></tr><tr>"; }
?>

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

<?
$source_img= $list[$i][file][0][file]; // 이미지 새창 띄울때 사용

$source_img_url = "$g4[path]/data/file/$bo_table/".urlencode($list[$i][file][0][file]); // 원본이미지
$no_img = "$latest_skin_path/img/no_image.gif"; // (첫번째) 이미지가 없는경우
  $thumb = $thumb_path.'/'.$list[$i][wr_id];   // 섬네일 이미지


// -- 썸네일이미지 사이즈 구하기  ★★★★★ 새로 추가
$thumb_size = getimagesize($thumb);
$thumb_w = $thumb_size[0];
$thumb_h = $thumb_size[1];


// ------ 이미지 출력하기 start
  if (file_exists($thumb)) {  // ★★★★★ 썸네일의 크기가 작은경우, 원본이미지 가져오기

if($thumb_w < $thu_width){
$img = "<img src='$source_img_url' width='$thu_width' height='$thu_height' border='0'>";
}else{
    $img = "<img src='$thumb' width='$thu_width' height='$thu_height' border='0'>";
}
}


if(!file_exists($thumb) && ($source_img))
$img = "<img src='$source_img_url' width='$thu_width' height='$thu_height' border='0'>";

    if (!file_exists($thumb) && !($source_img))
        $img = "<img src='$no_img' width='$thu_width' height='$thu_height' border=0 style='border:0px solid #333333;'>";
// ------ 이미지 출력하기 END


echo "<div style='position:relative; width:$thu_width; height:$height; left:3px; top:3px; border:#333 0px solid; background-color:white'>";

echo "<a href='{$list[$i][href]}'>". $img ."</a>";
echo "</div>";

  echo "<div style='margin-top:5px; width:$thu_width;'><span style='font:normal 11px dotum, 돋움; color:#333;'>{$link_url}". cut_str(get_text($list[$i][subject]), 25, '...') ."</a></span></div>";
?>

</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>
전체 66,554 |RSS
그누4 질문답변 내용 검색

회원로그인

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