Animated GIF restructuring, ImageMagick only used for resizing animated sequences.

This commit is contained in:
Mikael Nordfeldth 2015-01-25 22:56:55 +01:00
parent 2a7d45c986
commit a8e613e508
3 changed files with 11 additions and 30 deletions

View File

@ -386,7 +386,7 @@ class File extends Managed_DataObject
{ {
// Get some more information about this file through our ImageFile class // Get some more information about this file through our ImageFile class
$image = ImageFile::fromFileObject($this); $image = ImageFile::fromFileObject($this);
if ($image->animated && !common_config('image', 'resize_animated')) { if ($image->animated && is_null(common_config('thumbnail', 'animated'))) {
throw new UseFileAsThumbnailException($this->id); throw new UseFileAsThumbnailException($this->id);
} }

View File

@ -131,8 +131,7 @@ $default =
'delete' => false, 'delete' => false,
'move' => true), 'move' => true),
'image' => 'image' =>
array('jpegquality' => 85, array('jpegquality' => 85),
'resize_animated' => false), // true doesn't mean we _can_, only that we will _try_ (plugins might do it)
'avatar' => 'avatar' =>
array('server' => null, array('server' => null,
'dir' => INSTALLDIR . '/avatar/', 'dir' => INSTALLDIR . '/avatar/',
@ -258,7 +257,8 @@ $default =
array('crop' => false, // overridden to true if thumb height === null array('crop' => false, // overridden to true if thumb height === null
'maxsize' => 1000, // thumbs with an edge larger than this will not be generated 'maxsize' => 1000, // thumbs with an edge larger than this will not be generated
'width' => 450, 'width' => 450,
'height' => 600), 'height' => 600,
'animated' => null), // null="UseFileAsThumbnail", false="take still image". true requires ImageMagickPlugin
'application' => 'application' =>
array('desclimit' => null), array('desclimit' => null),
'group' => 'group' =>

View File

@ -34,32 +34,18 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* php5-imagick * php5-imagick
* *
* Provides: * Provides:
* Animated image support (for image/gif at least) * Animated GIF resize support
* *
* Suggestions: * Comments:
* After enabling the ImageMagick plugin, you might want to regenerate * Animated GIF resize requires setting $config['thumbnail']['animated'] = true;
* thumbnails for the newly support formats. This is easiest done with
* a script in the GNU social-bundled scripts directory:
* $ php scripts/clean_thumbnails.php
* *
* Bugs: * Bugs:
* Not even ImageMagick is very good at resizing animated GIFs. * Not even ImageMagick is very good at resizing animated GIFs.
* We are not infinitely fast, so resizing animated GIFs is _not_ recommended.
*/ */
class ImageMagickPlugin extends Plugin class ImageMagickPlugin extends Plugin
{ {
// configurable plugin options must be declared public
public $resize_animated = null;
public function initialize()
{
parent::initialize();
if (is_null($this->resize_animated)) {
$this->resize_animated = common_config('image', 'resize_animated');
}
}
/** /**
* @param ImageFile $file An ImageFile object we're getting metadata for * @param ImageFile $file An ImageFile object we're getting metadata for
* @param array $info The response from getimagesize() * @param array $info The response from getimagesize()
@ -76,12 +62,8 @@ class ImageMagickPlugin extends Plugin
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 // So far we only take over the resize for IMAGETYPE_GIF
// (and only animated for gifs!) // (and only animated for gifs! (and only if we really want to resize the animation!))
if ($imagefile->type == IMAGETYPE_GIF && $imagefile->animated) { if ($imagefile->type == IMAGETYPE_GIF && $imagefile->animated && common_config('thumbnail', 'animated')) {
if (!$this->resize_animated) {
// Don't resize if not desired, due to CPU/time limitations
return false;
}
$magick = new Imagick($imagefile->filepath); $magick = new Imagick($imagefile->filepath);
$magick = $magick->coalesceImages(); $magick = $magick->coalesceImages();
$magick->setIteratorIndex(0); $magick->setIteratorIndex(0);
@ -111,8 +93,7 @@ class ImageMagickPlugin extends Plugin
'homepage' => 'http://gnu.io/social', 'homepage' => 'http://gnu.io/social',
'rawdescription' => 'rawdescription' =>
// TRANS: Plugin description. // TRANS: Plugin description.
_m('Use ImageMagick for better image support.')); _m('Use ImageMagick for some more image support.'));
return true; return true;
} }
} }