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.
This commit is contained in:
Mikael Nordfeldth 2015-01-26 16:33:39 +01:00
parent 7beec74f0c
commit 67d09532dd
3 changed files with 10 additions and 5 deletions

View File

@ -382,12 +382,16 @@ class File extends Managed_DataObject
* *
* @return File_thumbnail * @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 // Get some more information about this file through our ImageFile class
$image = ImageFile::fromFileObject($this); $image = ImageFile::fromFileObject($this);
if ($image->animated && is_null(common_config('thumbnail', 'animated'))) { if ($image->animated && !common_config('thumbnail', 'animated')) {
throw new UseFileAsThumbnailException($this->id); // 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) { if ($width === null) {

View File

@ -113,7 +113,8 @@ class AttachmentListItem extends Widget
case 'image/jpg': case 'image/jpg':
case 'image/jpeg': case 'image/jpeg':
try { 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' => '')); $this->out->element('img', array('class'=>'u-photo', 'src' => $thumb->getUrl(), 'alt' => ''));
} catch (UseFileAsThumbnailException $e) { } catch (UseFileAsThumbnailException $e) {
$this->out->element('img', array('class'=>'u-photo', 'src' => $e->file->getUrl(), 'alt' => $e->file->title)); $this->out->element('img', array('class'=>'u-photo', 'src' => $e->file->getUrl(), 'alt' => $e->file->title));

View File

@ -258,7 +258,7 @@ $default =
'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 'animated' => false), // null="UseFileAsThumbnail", false="can use still frame". true requires ImageMagickPlugin
'application' => 'application' =>
array('desclimit' => null), array('desclimit' => null),
'group' => 'group' =>