ImageMagickPlugin refactored so we can more easily add new formats

This commit is contained in:
Mikael Nordfeldth 2015-03-04 12:06:21 +01:00
parent 284705eeb8
commit fe9dc8e901

View File

@ -51,7 +51,7 @@ class ImageMagickPlugin extends Plugin
* @param array $info The response from getimagesize() * @param array $info The response from getimagesize()
*/ */
public function onFillImageFileMetadata(ImageFile $imagefile) { public function onFillImageFileMetadata(ImageFile $imagefile) {
if (is_null($imagefile->animated) && $imagefile->type === IMAGETYPE_GIF) { if (is_null($imagefile->animated) && $imagefile->mimetype === 'image/gif') {
$magick = new Imagick($imagefile->filepath); $magick = new Imagick($imagefile->filepath);
$magick = $magick->coalesceImages(); $magick = $magick->coalesceImages();
$imagefile->animated = $magick->getNumberImages()>1; $imagefile->animated = $magick->getNumberImages()>1;
@ -60,10 +60,21 @@ class ImageMagickPlugin extends Plugin
return true; return true;
} }
public function onStartResizeImageFile(ImageFile $imagefile, $outpath, array $box) { public function onStartResizeImageFile(ImageFile $imagefile, $outpath, array $box)
// So far we only take over the resize for IMAGETYPE_GIF {
// (and only animated for gifs! (and only if we really want to resize the animation!)) switch ($imagefile->mimetype) {
if ($imagefile->type == IMAGETYPE_GIF && $imagefile->animated && common_config('thumbnail', 'animated')) { case 'image/gif':
// If GIF, then only for animated gifs! (and only if we really want to resize the animation!)
if ($imagefile->animated && common_config('thumbnail', 'animated')) {
return $this->resizeImageFileAnimatedGif($imagefile, $outpath, $box);
}
break;
}
return true;
}
protected function resizeImageFileAnimatedGif(ImageFile $imagefile, $outpath, array $box)
{
$magick = new Imagick($imagefile->filepath); $magick = new Imagick($imagefile->filepath);
$magick = $magick->coalesceImages(); $magick = $magick->coalesceImages();
$magick->setIteratorIndex(0); $magick->setIteratorIndex(0);
@ -82,8 +93,6 @@ class ImageMagickPlugin extends Plugin
return !$success; return !$success;
} }
return true;
}
public function onPluginVersion(&$versions) public function onPluginVersion(&$versions)
{ {