Skip to content

NCUBE.NET

  • 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 파일도 썸네일처리하지 않으면 크기가 같아지지 않아서 알아보던 중이었습니다.
    잘 쓰겠습니다.

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

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

Comments are closed.

Recent Posts

  • Windows 10 메모장의 재미난 기능
  • Windows 10 iCloud 사진 저장 폴더 변경
  • VS Code에서 git 히스토리 표시 오류
  • Windows 10 iTunes 백업 폴더 변경
  • Apache 서버에서 htaccess 파일 여러 개 지정하기
  • CentOS 7에서 Apache SELinux 설정
  • PSR 코딩을위해 VS Code 에 php-cs-fixer 적용
  • Instagram Basic Display API 연동
  • phpMyAdmin에서 root 로그인이 불가능한 경우 해결법
  • Ubuntu20.04 에서 PHP8 업그레이드

Recent Comments

  • 편리 on [PHP] HTTP와 PHP를 이용한 html5 video 스트리밍 구현
  • Kim on [PHP] HTTP와 PHP를 이용한 html5 video 스트리밍 구현
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 고맙습니다 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on PHPMailer를 이용한 이메일 발송
  • 초보자 on PHPMailer를 이용한 이메일 발송
  • 편리 on PHPMailer를 이용한 이메일 발송
  • 초보자 on PHPMailer를 이용한 이메일 발송
  • 편리 on 워드프레스 굿스플로 알림톡 플러그인 개발
  • 남민기 on 워드프레스 굿스플로 알림톡 플러그인 개발

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2021 NCUBE.NET | Built using WordPress and SuperbThemes