Skip to content

Instantly share code, notes, and snippets.

@octavian-nita
Created November 25, 2014 13:14
Show Gist options
  • Select an option

  • Save octavian-nita/8690304d17c02b5aaf10 to your computer and use it in GitHub Desktop.

Select an option

Save octavian-nita/8690304d17c02b5aaf10 to your computer and use it in GitHub Desktop.
[Koken](http://koken.me/) 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment