2026 년 4 월

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

 
그누스킨 그누소스 소스변경 소스문법 홈준비 기타
 
작성일 : 07-02-04 21:57
[그누소스] 썸네일 생성- 않으면서 빠르게 출력
 글쓴이 : Morning (124.♡.112.157)
조회 : 3,326  
   http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=10075&page=&s… [1543]
### 그누폐인님의 요청에 따라 기능을 보강하여 원본을 수정하였습니다.
### 추가된 옵션 $copy_rule 값이 비엇거나 width이면 너비를 기준으로 하여 정렬합니다.
### 추가된 옵션 $copy_rule 값이 height이면 높이를 기준으로 하여 정렬합니다.
### 추가된 옵션 $copy_pos 값이 비엇거나 1이면 원본이미지의 왼쪽이나 상단을 기준으로 정렬합니다.
### 추가된 옵션 $copy_pos 값이2이면 원본이미지의 중앙을 기준으로 정렬합니다.
### 추가된 옵션 $copy_pos 값이3이면 원본이미지의 오른쪽이나 하단을 기준으로 정렬합니다.

리스트 스킨 같은 곳에서 이미지 썸네일을 쉽게 만들고 보여주는 방법입니다.
이미 썸네일이 만들어져 있으면 재작업을 하지 않으며,
크기에 따른 개별적 썸네일을 만들수 있으며,
썸네일끼리 영향을 받지 않으며,
브라우져 캐쉬에도 영향을 받지 않습니다.

lib 디렉토리 내의 적당한 라이브러리 파일에 다음 두 함수를 추가합니다.

//원본이미지의 경로, 크기, 높이, 타입을 알 경우에 사용가능
function make_smallimg ($src, $src_w, $src_h, $src_t, $copy, $copy_w, $copy_h, $copy_rule='width', $copy_pos='1'){

  if ($src_t == 1)
    $src = @imagecreatefromgif($src);
  else if ($src_t == 2)
    $src = @imagecreatefromjpeg($src);
  else if ($src_t == 3)
    $src = @imagecreatefrompng($src);
  else
    return false;

  if (empty($src)) return false;
  if (empty($copy) || $copy_w < 10 || $copy_h < 10) return false;

  $src_x = 0;
  $src_y = 0;
  $copy_x = 0;
  $copy_y = 0;

  if ($copy_rule == 'width' || empty($copy_rule)) {//너비에 맞춤

    $rate = $src_h / $src_w;
    $new_w = $copy_w;
    $new_h = (int) ($rate * $copy_w);

    if ($new_h < $copy_h){//만들어질 썸네일 높이가 비율대로 줄여진 높이보다 클경우 가운데 위치시킴

      $copy_y = (int) (($copy_h - $new_h) / 2);
    }
    else {

      if ($copy_pos == '1' || empty($copy_pos)) {//원본에서 상단을 기준으로 가져옴

        //기본값 그대로
      }
      else if ($copy_pos == '2') {//원본에서 중앙을 기준으로 가져옴

        $temp_h = (int) ($copy_h / $copy_w * $src_w);
        $src_y = (int) (($src_h - $temp_h) / 2);
      }
      else if ($copy_pos == '3') {//원본에서 하단을 기준으로 가져옴

        $temp_h = (int) ($copy_h / $copy_w * $src_w);
        $src_y = $src_h - $temp_h;
      }
    }
  }
  else {//높이에 맞춤

    $rate = $src_w / $src_h;
    $new_h = $copy_h;
    $new_w = (int) ($rate * $copy_h);

    if ($new_w < $copy_w){//만들어질 썸네일 너비가 비율대로 줄여진 너비보다 클경우 가운데 위치시킴

      $copy_x = (int) (($copy_w - $new_w) / 2);
    }
    else {

      if ($copy_pos == '1' || empty($copy_pos)) {//원본에서 왼쪽을 기준으로 가져옴

        //기본값 그대로
      }
      else if ($copy_pos == '2') {//원본에서 중앙을 기준으로 가져옴

        $temp_w = (int) ($copy_w / $copy_h * $src_h);
        $src_x = (int) (($src_w - $temp_w) / 2);
      }
      else if ($copy_pos == '3') {//원본에서 오른쪽을 기준으로 가져옴

        $temp_w = (int) ($copy_w / $copy_h * $src_h);
        $src_x = $src_w - $temp_w;
      }
    }
  }

  $dst = @imagecreatetruecolor($copy_w, $copy_h);
  if (empty($dst)) return false;

  $background_color = @imagecolorallocate($dst, 255, 255, 255);
  if (empty($background_color)) return false;

  imagefilledrectangle($dst, 0, 0, $copy_w, $copy_h, $background_color);   
  imagecopyresampled($dst, $src, $copy_x, $copy_y, $src_x, $src_y, $new_w, $new_h, $src_w, $src_h);

  imagepng($dst, $copy);
  chmod($copy, 0606);
  return true;
}

//리스트스킨에서 썸네일을 보여줄때 사용
function get_smallimg_in_list($bo_table, $file, $num, $w, $h, $error_img, $style='', $copy_rule='width', $copy_pos='1'){

  global $g4;

  $temp_origine_img = "$g4[path]/data/file/$bo_table/" . urlencode($file[$num]['file']);

  if (empty($bo_table) || empty($file[$num]) || !is_file($temp_origine_img) || $w < 10 || $h < 10) {

    $temp_small = false;
  }
  else {

    if (empty($file[$num]['image_width']) || empty($file[$num]['image_height']) || empty($file[$num]['image_type'])) {

      $temp = getimagesize($temp_origine_img);
      $temp_origine_img_w = $temp[0];
      $temp_origine_img_h = $temp[1];
      $temp_origine_img_t = $temp[2];
    }
    else {

      $temp_origine_img_w = $file[$num]['image_width'];
      $temp_origine_img_h = $file[$num]['image_height'];
      $temp_origine_img_t = $file[$num]['image_type'];
    }

    $temp_small_img_w = $w;
    $temp_small_img_h = $h;
    $temp_small_dir = "$g4[path]/data/file/$bo_table/smallimg";

    if (!is_dir($temp_small_dir)){

      mkdir($temp_small_dir) or die('썸네일을 저장할 디렉토리를 생성할수 없습니다.');
    }

    $temp_small_img = "$temp_small_dir/s_{$temp_small_img_w}_{$temp_small_img_h}_" . urlencode($file[$num][file]);

    if (is_file($temp_origine_img) && !is_file($temp_small_img)) {

      $temp_small = make_smallimg ($temp_origine_img, $temp_origine_img_w, $temp_origine_img_h, $temp_origine_img_t, $temp_small_img, $temp_small_img_w, $temp_small_img_h, $copy_rule, $copy_pos);
    }
    else if (is_file($temp_origine_img) && is_file($temp_small_img)){

      $temp_small = true;
    }
    else {

      $temp_small = false;
    }
  }

  if ($temp_small) {

    return "<img src='$temp_small_img' width='$temp_small_img_w' height='$temp_small_img_h' border=0 $style onError=\"this.src='$error_img';\">";
  }
  else {

    return "<img src='$error_img' width='$w' height='$h' border=0 $style>";
  }
}


그리고 해당 리스트 스킨에서 

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

아래에 적당한 위치에 이미지를 출력할 부분에

아래와 같이 넣으면 됩니다.

<?=get_smallimg_in_list($board['bo_table'], $list[$i]['file'], 0, 75, 50, '/img/errorimg.gif', 'style="border:1px solid #000000;"', 'width', '1')?>

위에서 0, 75, 50, '/img/errorimg.gif', 'width', '1' 부분만 설명하면(나머진 그대로 하면 됩니다.)
0은 업로드 된 이미지중 몇번째 것을 썸네일로 보여줄것인지 지정합니다. 0, 1, 2, 3, 4 등이 올수 있습니다.
75는 만들어질 썸네일을 너비 입니다.
50은 만들어질 썸네일의 높이 입니다.
'/img/errorimg.gif' 은 이미지가 없거나 썸네일 생성 실패시 대신 보여줄 이미지 입니다.
'width' 는 너비와 높이중 어느것을 기준으로 할것인지 지정한것입니다. 썸네일로 보여질 모양이 너비가 길면' width', 높이가 길면 'height'로 하는 것이 좋습니다.
'1' 만들어질 썸네일의 비율보다 높이나 너비가 클경우 어느 부분을 짤라올것인지 결정합니다. '1'은 왼쪽이나 상단, '2'는 중앙, '3'은 오른쪽이나 하단을 기준으로 잘라옵니다.
주님과 함께 모닝커피를

Morning 07-02-04 22:00
 124.♡.112.157  
단순히 본문으로 가게 하기 위해선

<a href='<?=$list[$i][href]?>' <?=$style?>><?=get_smallimg_in_list($board['bo_table'], $list[$i]['file'], 0, 75, 50, '/img/errorimg.gif', 'style="border:1px solid #000000;"')?></a>

요렇게만 해주면 됩니다.

그리고 이미지 보기창을 사용할려면 조금은 복잡한데요

해당 스킨에 아래 스크립트를 그대로 복사해서 넣습니다.

<script language="JavaScript">
//기존 image_window를 이미지 정보로서 사용되도록 조금 수정한것입니다
//이미지 url, 이미지 너비, 이미지 높이
function image_window_with_info(img_url, img_w, img_h)
{
    var w = img_w; 
    var h = img_h; 
    var winl = (screen.width-w)/2; 
    var wint = (screen.height-h)/3; 

    if (!img_url || !img_w || !img_h){

      return;
    }

    if (w >= screen.width) { 
        winl = 0; 
        h = (parseInt)(w * (h / w)); 
    } 

    if (h >= screen.height) { 
        wint = 0; 
        w = (parseInt)(h * (w / h)); 
    } 

    var js_url = "<script language='JavaScript1.2'> \n"; 
        js_url += "<!-- \n"; 
        js_url += "var ie=document.all; \n"; 
        js_url += "var nn6=document.getElementById&&!document.all; \n"; 
        js_url += "var isdrag=false; \n"; 
        js_url += "var x,y; \n"; 
        js_url += "var dobj; \n"; 
        js_url += "function movemouse(e) \n"; 
        js_url += "{ \n"; 
        js_url += "  if (isdrag) \n"; 
        js_url += "  { \n"; 
        js_url += "    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; \n"; 
        js_url += "    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y; \n"; 
        js_url += "    return false; \n"; 
        js_url += "  } \n"; 
        js_url += "} \n"; 
        js_url += "function selectmouse(e) \n"; 
        js_url += "{ \n"; 
        js_url += "  var fobj      = nn6 ? e.target : event.srcElement; \n"; 
        js_url += "  var topelement = nn6 ? 'HTML' : 'BODY'; \n"; 
        js_url += "  while (fobj.tagName != topelement && fobj.className != 'dragme') \n"; 
        js_url += "  { \n"; 
        js_url += "    fobj = nn6 ? fobj.parentNode : fobj.parentElement; \n"; 
        js_url += "  } \n"; 
        js_url += "  if (fobj.className=='dragme') \n"; 
        js_url += "  { \n"; 
        js_url += "    isdrag = true; \n"; 
        js_url += "    dobj = fobj; \n"; 
        js_url += "    tx = parseInt(dobj.style.left+0); \n"; 
        js_url += "    ty = parseInt(dobj.style.top+0); \n"; 
        js_url += "    x = nn6 ? e.clientX : event.clientX; \n"; 
        js_url += "    y = nn6 ? e.clientY : event.clientY; \n"; 
        js_url += "    document.onmousemove=movemouse; \n"; 
        js_url += "    return false; \n"; 
        js_url += "  } \n"; 
        js_url += "} \n"; 
        js_url += "document.onmousedown=selectmouse; \n"; 
        js_url += "document.onmouseup=new Function('isdrag=false'); \n"; 
        js_url += "//--> \n"; 
        js_url += "</"+"script> \n"; 

    var settings;

    if (g4_is_gecko) {
        settings  ='width='+(w+10)+','; 
        settings +='height='+(h+10)+','; 
    } else {
        settings  ='width='+w+','; 
        settings +='height='+h+','; 
    }
    settings +='top='+wint+','; 
    settings +='left='+winl+','; 
    settings +='scrollbars=no,'; 
    settings +='resizable=yes,'; 
    settings +='status=no'; 


    win=window.open("","image_window",settings); 
    win.document.open(); 
    win.document.write ("<html><head> \n<meta http-equiv='imagetoolbar' CONTENT='no'> \n<meta http-equiv='content-type' content='text/html; charset="+g4_charset+"'>\n"); 
    var size = "이미지 사이즈 : "+w+" x "+h;
    win.document.write ("<title>"+size+"</title> \n"); 
    if(w >= screen.width || h >= screen.height) { 
        win.document.write (js_url); 
        var click = "ondblclick='window.close();' style='cursor:move' title=' "+size+" \n\n 이미지 사이즈가 화면보다 큽니다. \n 왼쪽 버튼을 클릭한 후 마우스를 움직여서 보세요. \n\n 더블 클릭하면 닫혀요. '"; 
    } 
    else 
        var click = "onclick='window.close();' style='cursor:pointer' title=' "+size+" \n\n 클릭하면 닫혀요. '"; 
    win.document.write ("<style>.dragme{position:relative;}</style> \n"); 
    win.document.write ("</head> \n\n"); 
    win.document.write ("<body leftmargin=0 topmargin=0 bgcolor=#dddddd style='cursor:arrow;'> \n"); 
    win.document.write ("<table width=100% height=100% cellpadding=0 cellspacing=0><tr><td align=center valign=middle><img src='"+img_url+"' width='"+w+"' height='"+h+"' border=0 class='dragme' "+click+"></td></tr></table>");
    win.document.write ("</body></html>"); 
    win.document.close(); 

    if(parseInt(navigator.appVersion) >= 4){win.window.focus();} 
}
</script>

그런다음 이미지 출력하는 부분에
아래내용을 복사해넣고
적당히 값을 수정해서 사용하시면 됩니다.

      <?

        $temp_num = 1;//몇번째 이미지를 사용할것인가 0, 1, 2, 3, 4 중하나
        $temp_copy_w = 75;//썸네일 너비
        $temp_copy_h = 50;//썸네일 높이
        $temp_error_img = 'http://8bong.com/skin/board/gallery/img/noimage.gif';
        $temp_style = " style=\"cursor:pointer; border:1px solid #000000;\"";
        $temp_copy_rule = 'width';
        $temp_copy_pos = '1';

        //이하 수정할 필요없습니다. 변수명이 복잡하여 줄인것 뿐입니다.
        $temp_img_w = $list[$i]['file'][$temp_num]['image_width'];
        $temp_img_h = $list[$i]['file'][$temp_num]['image_height'];
        $temp_img_url = $list[$i]['file'][$temp_num]['path'] . '/' . $list[$i]['file'][$temp_num]['file'];
        $temp_style .= " onclick=\"image_window_with_info('$temp_img_url', '$temp_img_w', '$temp_img_h');\"";

        echo get_smallimg_in_list($bo_table, $list[$i]['file'], $temp_num, $temp_copy_w, $temp_copy_h, $temp_error_img, $temp_style, $temp_copy_rule, $temp_copy_pos);
         
      ?>
Morning 07-02-12 12:10
 124.♡.110.121  
// http://www.sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=2588&sca=&sfl=wr_subject%7C%7Cwr_content&stx=%BD%E6%B3%D7%C0%CF&sop=and&page=1

$size = getimagesize($images_); 
 
if ($size[0] < 600){          //가로가 600보다 작을때 
  if ($size[1] > 450){        //세로가 450보다 크면 
      $size1 = 450 ;          //세로를 450에 맞춘다 
      $size0 = ceil( $size[0] * ( 450 / $size[1] ) );      //세로가 줄어든 비율에 따라 가로를 줄인다 
    } else {                    //세로가 450보다 안크면 
      $size1 = $size[1];      //세로는 원래 사이즈 
      $size0 = $size[0];      //가로도 원래 사이즈- 가로가 600보다 작은경우내 이므로 
    } 
}else{                                                      //가로가 600이상일때 
  if (( $size[1] / $size[0] ) > (450 / 600)){    //  세로/가로 가  위에서 정한 창의비율 450/600 보다 크면 
      $size1 = 450 ;                                              //세로를먼저 500에 맞추고 
      $size0 = ceil( $size[0] * ( 450 / $size[1] ) );    //가로를 그 줄어든 비율에 따라 맞춘다 
      }else{                                                        //세로/가로 가  위에서 정한 창의비율 450/600 보다 작으면 
      $size0 = 600 ;                                                //가로를 600에 맞추고 
      $size1 = ceil( $size[1] * ( 600 / $size[0] ) );        //세로를 그 줄어든 비율에 따라 맞춘다 
  } 
}
 
 

Total 167
번호 제   목 글쓴이 날짜 조회
47 [그누소스] 도대체 안지워지는 유령 폴더,파일을 지워보… Morning 02-05 5299
46 [그누스킨] 재정관리스킨 Morning 02-03 3815
45 [그누스킨] morningThumb2Yf Morning 07-25 3295
44 [그누스킨] morningwebzin Morning 07-25 3088
43 [그누스킨] YmorningThumba,YmorningThumbab Morning 07-12 3097
42 [그누스킨] YmorningThumb2,YmorningThumb2b Morning 07-12 3419
41 [그누소스] 네비게이션 (1) Morning 02-17 4579
40 [그누소스] 홈관리메뉴 (1) Morning 02-16 3266
39 [그누스킨] morning_webzin3 Morning 02-13 3375
38 [그누소스] 블로그 최신글 Morning 02-12 4218
37 [홈준비] 웹진과제 Morning 02-06 4692
36 [소스문법] dq_thumb_engine2를 쓴 최신글스킨에서 썸네일 안… (1) Morning 02-04 4171
35 [그누소스] 생성한 썸네일을 스킨에서 몽땅 삭제하기 Morning 02-04 3485
34 [그누소스] 썸네일 생성- 않으면서 빠르게 출력 (2) Morning 02-04 3327
33 [소스문법] include() (5) Morning 02-03 5430
 1  2  3  4  5  6  7  8  9  10    

Therefore, holy brothers, who share in the heavenly calling,
fix your thoughts on Jesus, the apostle and high priest whom we confess.
Let us fix our eyes on Jesus, the author and perfecter of our faith,
who for the joy set before him endured the cross, scorning its shame,
and sat down at the right hand of the throne of God