From: Mikael Nordfeldth Date: Mon, 26 Jan 2015 15:33:39 +0000 (+0100) Subject: Improved animated image thumbnail freedom of choice X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=67d09532ddb324897d8222b5b8744b0118e72d70;p=quix0rs-gnu-social.git Improved animated image thumbnail freedom of choice Default is now to take still thumbnails of animated GIFs and then show them as originals in an AttachmentListItem. The still frames are mostly used with front-ends like qvitter. --- diff --git a/classes/File.php b/classes/File.php index 58b1b0ed89..ce2f940161 100644 --- a/classes/File.php +++ b/classes/File.php @@ -382,12 +382,16 @@ class File extends Managed_DataObject * * @return File_thumbnail */ - public function getThumbnail($width=null, $height=null, $crop=false) + public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true) { // Get some more information about this file through our ImageFile class $image = ImageFile::fromFileObject($this); - if ($image->animated && is_null(common_config('thumbnail', 'animated'))) { - throw new UseFileAsThumbnailException($this->id); + if ($image->animated && !common_config('thumbnail', 'animated')) { + // null means "always use file as thumbnail" + // false means you get choice between frozen frame or original when calling getThumbnail + if (is_null(common_config('thumbnail', 'animated')) || !$force_still) { + throw new UseFileAsThumbnailException($this->id); + } } if ($width === null) { diff --git a/lib/attachmentlistitem.php b/lib/attachmentlistitem.php index 3764c827cb..919727bc1f 100644 --- a/lib/attachmentlistitem.php +++ b/lib/attachmentlistitem.php @@ -113,7 +113,8 @@ class AttachmentListItem extends Widget case 'image/jpg': case 'image/jpeg': try { - $thumb = $this->attachment->getThumbnail(); + // Tell getThumbnail that we can show an animated image if it has one (4th arg, "force_still") + $thumb = $this->attachment->getThumbnail(null, null, false, false); $this->out->element('img', array('class'=>'u-photo', 'src' => $thumb->getUrl(), 'alt' => '')); } catch (UseFileAsThumbnailException $e) { $this->out->element('img', array('class'=>'u-photo', 'src' => $e->file->getUrl(), 'alt' => $e->file->title)); diff --git a/lib/default.php b/lib/default.php index 9ca7760280..396e409e6d 100644 --- a/lib/default.php +++ b/lib/default.php @@ -258,7 +258,7 @@ $default = 'maxsize' => 1000, // thumbs with an edge larger than this will not be generated 'width' => 450, 'height' => 600, - 'animated' => null), // null="UseFileAsThumbnail", false="take still image". true requires ImageMagickPlugin + 'animated' => false), // null="UseFileAsThumbnail", false="can use still frame". true requires ImageMagickPlugin 'application' => array('desclimit' => null), 'group' =>