알짜게시판

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

번호 제목 글쓴이 조회 날짜
58 [PHP] REQUEST 값 받기(application/json 포함) 4,270 04-20
57 [Linux] 데몬(systemd service) 작성 및 실행하기 28,116 03-14
56 [MySQL] 업데이트 이후 에러 발생([ERROR] Incorrect definition of table … 90,369 12-08
55 구글 크롬 탭검색 비활성화 71,012 12-04
54 [MySQL] MySQL, MariaDB 업데이트 72,760 11-24
53 [아이폰] HTTPS 감청 우회하기 100,529 11-01
52 Windows에 Rust 설치하기 56,510 10-05
51 [ReactNative] android directory was detected in the project. 64,670 07-20
50 [리눅스] 메일(Mail) 삭제/초기화 57,390 07-18
49 [Delphi] 윈도우 알림센터에 메시지 출력하기 54,530 06-20
48 텔레그램 봇 (Telegram Bot) 만들기 37,251 05-03
47 [부트스트랩] nav 에서 하위 항목 활성화 시 부모 항목 활성화 34,356 04-30
46 [리눅스] PHP 버전 추가하기 34,007 04-29
45 [PHP] Curl 접속 속도가 늦은 경우 35,680 04-10
44 [윈도우] 파일 내용 검색 45,034 02-09
43 [MySQL] unblock with 'mysqladmin flush-hosts' 에러 53,000 01-01
42 [ReactNative] 캐시 초기화 하는 방법 55,438 12-27
41 [윈도우] node.js 와 npm 업데이트(업그레이드) 56,744 12-01
40 [윈도우] 윈도우11 시작 메뉴 위치 변경(가운데, 왼쪽) 59,893 10-10
39 [Delphi] 중복 실행 방지 58,390 09-21
38 [리눅스] yum 에서 Thread died in Berkeley DB library 오류 58,096 09-18
37 [리눅스] VNSTAT 설치하기 55,496 09-17
36 [리눅스] 로그 삭제 및 비우기(?) 56,846 09-09
35 [FTP] 500 Illegal PORT command. 46,684 09-03
34 [리눅스] .htaccess 를 이용해서 https 이동하기 44,862 08-31
열람 [PHP] Imagek 를 이용한 썸네일 생성 45,304 08-26
32 [그누보드] 1364 : Field 'xxxxx' doesn't have a default value 44,754 08-20
31 [리눅스] 윈도우 프로그램 실행 (centos7, wine 7.0) 44,176 08-09
30 [윈도우] IPv6 켜기, 끄기 43,424 08-03
29 [그누보드] 회원 가입일 기준으로 이용기간 정하기 40,716 07-28
28 [그누보드] sql_fetch, sql_query 안쓰고 직접 mysql 사용하기 40,350 07-24
목록