Imagek 를 이용한 썸네일 생성

<?php
// Imagik 를 이용한 썸네일 생성
function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height)
{
   $thumbname = 'thumb-'.preg_replace("/\.[^\.]+$/i", "", $filename).'_'.$thumb_width.'x'.$thumb_height.'.png';

   $thumb_file = $target_path.'/'.$thumbname;
   if(is_file($thumb_file)) return $thumbname;

   $source_file = $source_path.'/'.$filename;
   if(!is_file($source_file)) return;

   $img = new Imagick($source_file);

   $img->thumbnailImage($thumb_width, $thumb_height);

   $img->setImageFormat('png');
   $img->writeImage($thumb_file);

   return $thumbname;
}

// 사용하기
$thumbname = thumbnail('원본파일명', '원본파일경로', '썸네일저장경로', '썸네일 넓이', '썸네일 높이');
if($thumbname)
{
   header('Expires: '.gmdate('D, d M Y H:i:s', time()+(60*60*24*365)).' GMT');
   header('Cache-Control: max-age='.(60*60*24*365));
   header('Pragma: public');
   header('Content-Type: image/png');

   $fp = fopen($filepath.'/'.$thumbname, 'rb');
   if (!fpassthru($fp)) fclose($fp);
}

Comments

Tips & Tech

Others [FTP] 500 Illegal PORT command.
Linux .htaccess 를 이용해서 https 이동하기
Views Dev tips Imagek 를 이용한 썸네일 생성
Dev tips 파일 포맷 알아내기
GnuBoard 1364 : Field 'xxxxx' doesn't have a default value
GnuBoard 웹폰트 적용하기
GnuBoard CKEditor 5 플러그인
Linux 윈도우 프로그램 실행 (centos7, wine 7.0)
Kilho.net [시크릿DNS] 프록시 혼합 사용 예제
Windows IPv6 켜기, 끄기
GnuBoard 회원 가입일 기준으로 이용기간 정하기
GnuBoard sql_fetch, sql_query 안쓰고 직접 mysql 사용하기
Linux 웹서버 상태 확인 후 자동 재시작 쉘 스크립트
Kilho.net WinDivert 1753 에러 발생시
Dev tips PHP 수정시 적용이 안되는 경우 해결 (opcache 중지)
Others [맥OS] 마우스 휠 스크롤 방향 윈도우와 일치시키는 방…
Dev tips [Ruby] 윈도우에서 pod install 실행시 UTF-8 오류
Dev tips [Ruby] Could not open library 'libcurl'
Kilho.net WinDivert 서비스 종료
Dev tips [Android] Error type 3: Activity class {com.?.MainAc…
Windows 윈도우 서버 2016 IIS 중지
GnuBoard 새 글 정리하기
Dev tips WinDivert 오류코드
Dev tips Curl 을 이용하여 파일 다운로드
Dev tips Curl 을 이용하여 json 을 post 보내기
GnuBoard CKEditor 5 플러그인
Kilho.net 칼무리 자동실행이 안 되는 원인를 찾았습니다
Dev tips 워드프레스와 그누보드 연동 모듈
Windows 설치하려고 하는 앱이 Microsoft에서 확인된 앱이 아닙…
Delphi 권한상승