octavian-nita
11/25/2014 - 1:14 PM

[Koken](http://koken.me/) plugin sample

Koken plugin sample

<?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);
    }
}