알짜게시판

[PHP] Imagek 를 이용한 썸네일 생성

[code]
<?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);
}
[/code]

번호 제목 글쓴이 조회 날짜
223 [시크릿DNS] 프록시 혼합 사용 예제 1 249,157 08-07
222 [아이폰] HTTPS 감청 우회하기 101,146 11-01
221 [칼무리] 영역화면 크기 오류인 경우 94,361 12-12
220 [그누보드] CKEditor 5 플러그인 91,016 08-11
219 [그누보드] 사이드바 만들기 90,388 05-04
218 [MySQL] 업데이트 이후 에러 발생([ERROR] Incorrect definition of table … 90,374 12-08
217 [시크릿DNS] Kaspersky 백신 사용시 DNS 암호화 관련 4 83,183 01-04
216 [MySQL] MySQL, MariaDB 업데이트 72,762 11-24
215 ChangeDNS - DNS 서버를 손쉽게 변경합니다. 71,284 08-13
214 구글 크롬 탭검색 비활성화 71,016 12-04
213 [ReactNative] android directory was detected in the project. 64,670 07-20
212 killer 네트워크 이슈 팁 1 64,163 12-04
211 HTTPS/DNS 차단 쉽게 이해하기 61,527 08-16
210 [그누보드] Syntax Highlight 적용하기 60,556 05-19
209 [윈도우] 윈도우11 시작 메뉴 위치 변경(가운데, 왼쪽) 59,894 10-10
208 [Delphi] 중복 실행 방지 58,394 09-21
207 [리눅스] yum 에서 Thread died in Berkeley DB library 오류 58,103 09-18
206 [리눅스] 메일(Mail) 삭제/초기화 57,395 07-18
205 [리눅스] 로그 삭제 및 비우기(?) 56,852 09-09
204 [윈도우] node.js 와 npm 업데이트(업그레이드) 56,747 12-01
203 [그누보드] 아이디 대신 이메일로 회원 가입하기 56,654 02-02
202 Windows에 Rust 설치하기 56,514 10-05
201 [그누보드] 훅을 통한 글쓰기, 댓글 알림 56,234 05-26
200 [리눅스] VNSTAT 설치하기 55,497 09-17
199 [ReactNative] 캐시 초기화 하는 방법 55,444 12-27
198 [Delphi] 윈도우 알림센터에 메시지 출력하기 54,533 06-20
197 [MySQL] unblock with 'mysqladmin flush-hosts' 에러 53,003 01-01
196 [Delphi] 파일 포맷 알아내기 50,848 09-08
195 [FTP] 500 Illegal PORT command. 46,694 09-03
194 [그누보드] 웹폰트 적용하기 45,483 08-13
열람 [PHP] Imagek 를 이용한 썸네일 생성 45,306 08-26