사이트 내 전체검색
그누보드
[팁] 베르쿠치님이 질문하신 최신글의 제목 TEXT를 이미지로 처리하기
로빈아빠
https://cmd.kr/gnu/240 URL이 복사되었습니다.

본문

최신글에서제목을 이미지로 처리하여 (폰트,강조등) 보기좋게 만드는 내용입니다.


1. latest.skin.php 를 다음과 같이 만듭니다. (스킨명:gl.img.onerow)

<?
// 전달방법 : 테이블명,wr_id 를 | 로 구별해서 여러 줄 가능 $bo_table|$wr_id\n
$arr_opt=explode("\n",$options);
$thumb_width=140;
$thumb_height=100;
$thumb_title_width=450;
$thumb_title_height=25;
$thumb_title_font_size=15;
$thumb_title_font="yungo330.ttf";
global $rand; //레이어 번호때문에..
?>
<?
$iii=1;
foreach($arr_opt as $str) {
 $arr2=explode("|",$str);
 $bo_table=$arr2[0];
 $wr_id=intval($arr2[1]);
 if (!$bo_table||!$wr_id) continue;

 $tmp_write_table = $g4[write_prefix] . $bo_table;
 $row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$wr_id' ");
 if (!$row2) continue;

 $data_path = $g4[path]."/data/file/$bo_table";
 $thumb_path = "$g4[path]/data/tmp";;
 gl_check_dir($thumb_path); //디렉토리 생성 glite/lib.php 에 있음..

 $file=get_file($row[bo_table], $row2[wr_id]);
 //var_dump($file);

 $thumb="";
 for ($i2=0; $i2<15; $i2++) {
  $filename = $file[$i2][file]; //원본
  if (!$filename) continue;
  if ( !preg_match("/\.(jp[e]?g|gif|png)$/i", $filename)) continue;
  $filename2=$data_path."/".$filename;
  if (!file_exists($filename2)) continue;
  //echo "$filename<BR>";

  $thumb=$thumb_path."/tmp.thumb.$thumb_width.$thumb_height.".$filename;

  if (!file_exists($thumb) || filemtime($filename2) > filemtime($thumb) ||$_GET[recalc]) {
   //echo "갱신... $filename $thumb<BR>";
   //echo "$filename -> $thumb<BR>";
   //$thumb2=thumbnail($filename, $thumb_width,$thumb_height, $is_create=true, $is_crop=2, $quality, $small_thumb=true, $watermark, $filter="", $noimg="", $thumb_type="");
   createThumb($thumb_width, $thumb_height, $filename2, $thumb, $is_crop=true,$quality=80,$force=false);
  }

  if (!file_exists($thumb)) $thumb="";
  break;
 }

 //섬네일 없으면 본문이미지중에서 찾기
 if (!$thumb) $thumb=gl_extract_img($row2[wr_content]);
 if (!$thumb) $thumb="/img/blank.gif";

 ?>

  <div id="left_menudiv_<?=$rand?>_<?=$iii?>" style="DISPLAY: none;">

  <span style="float:left;width:155"><img src='<?=$thumb?>' width=<?=$thumb_width?> height=<?=$thumb_height?>></span>
  <span>
   <div style="height:25">
    <span style="float:left;height:25">
    <a href='<?=$g4[bbs_path]?>/?bd=<?=$bo_table?>&wr_id=<?=$row2[wr_id]?>'
    title='<?=$row2[wr_subject]?>'><?
    $thumb_title_img=$thumb_path."/tmp.thumb.title.$bo_table.$wr_id.gif";
    make_text_img($thumb_title_img,$row2[wr_subject],$thumb_title_width,$thumb_title_height,$thumb_title_font_size,$thumb_title_font);
    echo "<img src=$thumb_title_img width=$thumb_title_width height=$thumb_title_height border=0></a>";
    ?>
    </span>

    <span style="float:right">
    <? if ($iii<=1) { ?>
     <img src='/glite/img/btn_pre_x.gif'>
    <? } else { ?>
     <img src='/glite/img/btn_pre.gif' style='cursor:hand;' onclick=view_menu_over2(<?=$rand?>,-2)>
    <? } ?>
    <? if ($iii>=count($arr_opt)) { ?>
     <img src='/glite/img/btn_next_x.gif'>
    <? } else { ?>
     <img src='/glite/img/btn_next.gif' style='cursor:hand;' onclick=view_menu_over2(<?=$rand?>,-1)>
    <? } ?>
    </span>
   </div>
 
   
   <div style='font-size:11pt;line-height:22px;'>
   <?=cut_str(strip_tags2($row2[wr_content]),300)?>
   </div>
  </span>
  </div>

<?
 $iii++;
}
?>









2. lib 함수에 다음 함수를 추가합니다. (글자를 이미지로 만드는 함수..)
   물론 GD 라이버리가 지원되어야 합니다. 폰트 등등은 적당하게 조정





function make_text_img($imgname,$title,$width=300,$height=10,$size=11,$font="yungo330.ttf") {
 $im = ImageCreate ($width,$height); // 사이즈가 300x300인 이미지 생성

 $color_black = ImageColorAllocate ($im, 0xFF, 0xFF, 0xFF); // 배경 힌색
 $color_white = ImageColorAllocate ($im, 0x20, 0x20, 0x20); //   글씨 주황색

 ImageTTFtext($im, $size, 0, 0, 19, $color_white, $_SERVER['DOCUMENT_ROOT']."/font/$font", $title); // (100,150)에 글씨을 입력

 //글씨크기,글씨회전각도,좌표,좌표
 ImageGif($im,$imgname);
 ImageDestroy ($im); // 메모리에서 이미지 제거
 $im = imagecreatefromgif($imgname);
 return $imgname;
}



3. index.php 출력할 부분에서 다음과 같이 지정합니다.



 <?
  $options="info_food|4252|tip_gnu|110\ntip_gnu|109\ntip_gnu|108";
  $arr=explode("\n",$options);
  $div_count=count($arr);
 ?>

 
 <div style="position:relative; width:665px; height:100px; border:1px solid #EEEEEE; overflow:hidden;margin:0 0 10 0;font-family:나눔고딕,Tahoma,굴림;">
  <?=latest("gl.img.onerow", "notice", 10, 50,$options)?> 
 </div>


자동으로 움직이게하는 부분은 뺐습니다. 뭐 페이지 전환하는 스크립터로 적당하게 꾸미시면 되겠네요

급조해서 대충 사용하는 루틴이다보니 매끄럽지 못합니다.^^

댓글목록

베르쿠치님의 댓글

profile_image 베르쿠치 작성일

고맙습니다. 로빈아빠님. 귀하게 잘 쓰겠습니다.

한스님의 댓글

profile_image 한스 작성일

gl_check_dir($thumb_path); //디렉토리 생성 glite/lib.php 에 있음..
여기에서 에러가 나는데요?  위에 그대로 했는데 안되는데요

로빈아빠님의 댓글

profile_image 로빈아빠 작성일

gl_check_dir 함수가 없어서 그런것이네요..
다음 루틴을 소스에 넣어주세요.^^

function gl_check_dir($dir) {
if (!file_exists($dir)) {
@mkdir($dir, 0707);
@chmod($dir, 0707);
$f = @fopen($dir."/index.php", "w");
@fwrite($f, "");
@fclose($f);
@chmod($file, 0606);
}
}

그누보드
190 (1/4P)

Search

Copyright © Cmd 명령어 18.116.67.212