Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[PHP] 그누보드5 no image 썸네일 생성

2015-08-07 by 편리

갤러리 스킨 작업 중에 이미지 첨부가 없는 게시물의 경우 no image 라는 텍스트 문구를 출력하는 대신 썸네일 이미지를 생성하는 기능이 필요해서 아래 함수를 만들었다.

// NO IMAGE 썸네일
function get_noimage_thumbnail($bo_table, $noimg, $width, $height, $class='')
{
    $img_content = '<span style="width:'.$width.'px;height:'.$height.'px"';
    if($class)
        $img_content .= ' class="'.$class.'"';
    $img_content .= '>no image</span>';

    if(!is_file($noimg))
        return $img_content;

    $size = @getimagesize($noimg);
    if($size[2] < 1 || $size[2] > 3)
        return $img_content;

    $ext = array(1 => 'gif', 2 => 'jpg', 3 => 'png');

    $filename = 'no-image.'.$ext[$size[2]];
    $filepath = G5_DATA_PATH.'/file/'.$bo_table;

    $src_file = $filepath.'/'.$filename;
    if(!is_file($src_file)) {
        if(!copy($noimg, $src_file))
            return $img_content;

        @chmod($src_file, G5_FILE_PERMISSION);
    }

    $tname = thumbnail($filename, $filepath, $filepath, $width, $height, false, true);

    if(!$tname)
        return $img_content;

    return '<img src="'.G5_DATA_URL.'/file/'.$bo_table.'/'.$tname.'" width="'.$width.'" height="'.$height.'">';
}

게시판 스킨에 no_img.gif 등의 파일이 있어야 하고 이 파일의 절대 경로를 $noimg 값으로 넘겨주면 이 파일을 이용해 $width, $height 값에 대응하는 썸네일 파일이 생성되고 사용자 화면이 출력이 된다.

Post navigation

Previous Post:

벌써 윈도우 10 업데이트 공개?

Next Post:

2015년 8월 8일 하남~국수역 라이딩

2 Commments

  1. 휴먼 says:
    2020-10-25 at 17:55

    감사합니다.
    no-img.png 파일도 썸네일처리하지 않으면 크기가 같아지지 않아서 알아보던 중이었습니다.
    잘 쓰겠습니다.

    Reply
    1. 편리 says:
      2020-10-27 at 11:23

      안녕하세요.
      댓글 남겨주셔서 감사합니다.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes