알짜게시판

[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]

번호 제목 글쓴이 조회 날짜
212 HTTPS/DNS 차단 쉽게 이해하기 18,732 08-16
211 ChangeDNS - DNS 서버를 손쉽게 변경합니다. 19,404 08-13
210 [ReactNative] android directory was detected in the project. 29,015 07-20
209 [리눅스] 메일(Mail) 삭제/초기화 29,371 07-18
208 [Delphi] 윈도우 알림센터에 메시지 출력하기 40,773 06-20
207 [그누보드] 사이드바 만들기 49,504 05-04
206 텔레그램 봇 (Telegram Bot) 만들기 36,564 05-03
205 [부트스트랩] nav 에서 하위 항목 활성화 시 부모 항목 활성화 33,864 04-30
204 [리눅스] PHP 버전 추가하기 33,393 04-29
203 [PHP] Curl 접속 속도가 늦은 경우 34,920 04-10
202 [윈도우] 파일 내용 검색 44,420 02-09
201 [MySQL] unblock with 'mysqladmin flush-hosts' 에러 52,224 01-01
200 [ReactNative] 캐시 초기화 하는 방법 53,724 12-27
199 killer 네트워크 이슈 팁 1 59,405 12-04
198 [윈도우] node.js 와 npm 업데이트(업그레이드) 56,190 12-01
197 [윈도우] 윈도우11 시작 메뉴 위치 변경(가운데, 왼쪽) 59,351 10-10
196 [Delphi] 중복 실행 방지 57,828 09-21
195 [리눅스] yum 에서 Thread died in Berkeley DB library 오류 57,400 09-18
194 [리눅스] VNSTAT 설치하기 54,967 09-17
193 [리눅스] 로그 삭제 및 비우기(?) 55,681 09-09
192 [Delphi] 파일 포맷 알아내기 50,334 09-08
191 [FTP] 500 Illegal PORT command. 45,969 09-03
190 [리눅스] .htaccess 를 이용해서 https 이동하기 44,398 08-31
열람 [PHP] Imagek 를 이용한 썸네일 생성 44,808 08-26
188 [PHP] 파일 포맷 알아내기 44,639 08-23
187 [그누보드] 1364 : Field 'xxxxx' doesn't have a default value 44,339 08-20
186 [그누보드] 웹폰트 적용하기 44,775 08-13
185 [그누보드] CKEditor 5 플러그인 50,696 08-11
184 [리눅스] 윈도우 프로그램 실행 (centos7, wine 7.0) 43,412 08-09
183 [시크릿DNS] 프록시 혼합 사용 예제 1 117,594 08-07
182 [윈도우] IPv6 켜기, 끄기 42,585 08-03