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

Windows node.js 와 npm 업데이트(업그레이드)
Windows 윈도우11 시작 메뉴 위치 변경(가운데, 왼쪽)
Delphi 중복 실행 방지
Linux yum 에서 Thread died in Berkeley DB library 오류
Linux VNSTAT 설치하기
Linux 로그 삭제 및 비우기(?)
Others [FTP] 500 Illegal PORT command.
Linux .htaccess 를 이용해서 https 이동하기
Views Dev tips Imagek 를 이용한 썸네일 생성
GnuBoard 1364 : Field 'xxxxx' doesn't have a default value
Linux 윈도우 프로그램 실행 (centos7, wine 7.0)
Windows IPv6 켜기, 끄기
GnuBoard 회원 가입일 기준으로 이용기간 정하기
GnuBoard sql_fetch, sql_query 안쓰고 직접 mysql 사용하기
Dev tips PHP 수정시 적용이 안되는 경우 해결 (opcache 중지)
Others [맥OS] 마우스 휠 스크롤 방향 윈도우와 일치시키는 방…
Dev tips [Ruby] 윈도우에서 pod install 실행시 UTF-8 오류
Dev tips [Ruby] Could not open library 'libcurl'
Dev tips [Android] Error type 3: Activity class {com.?.MainAc…
Dev tips Curl 을 이용하여 파일 다운로드
Dev tips Curl 을 이용하여 json 을 post 보내기
Windows 설치하려고 하는 앱이 Microsoft에서 확인된 앱이 아닙…
Delphi Glyph 에 사용할 이미지 생성하기
Python 파이썬 아나콘다 업데이트
Delphi bsNone 인 폼에서 드래그 및 크기조절
Linux Composer 설치하기
Windows WinHTTP 사용에서 12175 에러 발생시
Dev tips 날짜필드 연장하기
Linux Swap 생성/수정
Linux 바이러스 검사