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

- 08-26
- 45,817 회
- 0 건
[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]
로그인 후 댓글내용을 입력해주세요