From bf666f8553d3c306b60d8a8334fd3035fd6a33fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 13 Nov 2014 23:30:34 +0100 Subject: [PATCH] FEATURE: allow animated thumbnails --- app/models/optimized_image.rb | 35 +++++++++++++++++++++++------------ app/models/upload.rb | 2 +- config/locales/server.en.yml | 1 + config/site_settings.yml | 1 + 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index 5df84700e..08ec00945 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -79,19 +79,30 @@ class OptimizedImage < ActiveRecord::Base end def self.resize(from, to, width, height, allow_animation=false) - from << "[0]" unless allow_animation # NOTE: ORDER is important! - instructions = %W{ - #{from} - -background transparent - -gravity center - -thumbnail #{width}x#{height}^ - -extent #{width}x#{height} - -interpolate bicubic - -unsharp 2x0.5+0.7+0 - -quality 98 - #{to} - }.join(" ") + instructions = if allow_animation + %W{ + #{from} + -coalesce + -gravity center + -thumbnail #{width}x#{height}^ + -extent #{width}x#{height} + -layers optimize + #{to} + }.join(" ") + else + %W{ + #{from}[0] + -background transparent + -gravity center + -thumbnail #{width}x#{height}^ + -extent #{width}x#{height} + -interpolate bicubic + -unsharp 2x0.5+0.7+0 + -quality 98 + #{to} + }.join(" ") + end `convert #{instructions}` diff --git a/app/models/upload.rb b/app/models/upload.rb index d9a5437df..9880acece 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -26,7 +26,7 @@ class Upload < ActiveRecord::Base def create_thumbnail!(width, height) return unless SiteSetting.create_thumbnails? - thumbnail = OptimizedImage.create_for(self, width, height) + thumbnail = OptimizedImage.create_for(self, width, height, allow_animation: SiteSetting.allow_animated_thumbnails) if thumbnail optimized_images << thumbnail self.width = width diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index db55448a8..7a555e7b7 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -975,6 +975,7 @@ en: allow_uploaded_avatars: "Allow users to upload custom avatars." allow_animated_avatars: "Allow users to use animated gif avatars. WARNING: run the avatars:refresh rake task after changing this setting." + allow_animated_thumbnails: "Generates animated thumbnails of animated gifs." automatically_download_gravatars: "Download Gravatars for users upon account creation or email change." digest_topics: "The maximum number of topics to display in the email digest." digest_min_excerpt_length: "Minimum post excerpt in the email digest, in characters." diff --git a/config/site_settings.yml b/config/site_settings.yml index 878ecdd37..24cb6906d 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -478,6 +478,7 @@ files: allow_animated_avatars: client: true default: false + allow_animated_thumbnails: false trust: default_trust_level: