about summary refs log tree commit diff
path: root/app/models/preview_card.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/preview_card.rb')
-rw-r--r--app/models/preview_card.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb
index 0c82f06ce..0ffa6b10f 100644
--- a/app/models/preview_card.rb
+++ b/app/models/preview_card.rb
@@ -34,7 +34,7 @@ class PreviewCard < ApplicationRecord
 
   has_and_belongs_to_many :statuses
 
-  has_attached_file :image, styles: { original: { geometry: '400x400>', file_geometry_parser: FastGeometryParser } }, convert_options: { all: '-quality 80 -strip' }
+  has_attached_file :image, styles: ->(f) { image_styles(f) }, convert_options: { all: '-quality 80 -strip' }
 
   include Attachmentable
 
@@ -52,6 +52,23 @@ class PreviewCard < ApplicationRecord
     save!
   end
 
+  class << self
+    private
+
+    def image_styles(f)
+      styles = {
+        original: {
+          geometry: '400x400>',
+          file_geometry_parser: FastGeometryParser,
+          convert_options: '-coalesce -strip',
+        },
+      }
+
+      styles[:original][:format] = 'jpg' if f.instance.image_content_type == 'image/gif'
+      styles
+    end
+  end
+
   private
 
   def extract_dimensions