Created
November 25, 2014 13:14
-
-
Save octavian-nita/8690304d17c02b5aaf10 to your computer and use it in GitHub Desktop.
[Koken](http://koken.me/) plugin sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class ThonResizer extends KokenPlugin | |
| { | |
| function __construct() | |
| { | |
| // Get information about the available graphics processing library: | |
| list($version, $lib) = Darkroom::processing_library_version(); | |
| // Only install the hook if Imagick is available (no GD support for the moment): | |
| if ($lib === 'Imagick') { | |
| $this->register_hook('content.create', 'create_featured_image'); | |
| log_message('debug', 'Featured image creation hook registered'); | |
| } else { | |
| log_message('debug', 'Imagick not available; featured image creation hook not registered'); | |
| } | |
| } | |
| /** | |
| * Creates a 185x170 thumbnail for the original image, by first resizing to fit the smaller edge and then cropping | |
| * around the center of the image. | |
| */ | |
| function create_featured_image($content) | |
| { | |
| // Ignore call if no content or content is not an image: | |
| if (!$content or !$content['mime_type'] or strpos($content['mime_type'], 'image') !== 0) { | |
| return; | |
| } | |
| $o_height = $content['original']['height']; | |
| $o_width = $content['original']['width']; | |
| $tw = 185; | |
| $th = 170; | |
| $original = 'false-blue.jpg'; | |
| $image = new Imagick($original); | |
| $image->cropThumbnailImage($tw, $th); | |
| $small_cover_name = pathinfo($original, PATHINFO_FILENAME) . ',small.' . pathinfo($original, PATHINFO_EXTENSION); | |
| $image->writeImage($small_cover_name); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment