mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:05:15 +08:00
FIX: uploading an animated user card/profile background was converted to a still image
This commit is contained in:
parent
7b94dc8586
commit
a3831a7003
|
@ -67,9 +67,10 @@ class UploadsController < ApplicationController
|
|||
|
||||
# allow users to upload large images that will be automatically reduced to allowed size
|
||||
if SiteSetting.max_image_size_kb > 0 && FileHelper.is_image?(filename) && File.size(tempfile.path) > 0
|
||||
allow_animation = type == "avatar" ? SiteSetting.allow_animated_avatars : SiteSetting.allow_animated_thumbnails
|
||||
attempt = 5
|
||||
while attempt > 0 && File.size(tempfile.path) > SiteSetting.max_image_size_kb.kilobytes
|
||||
OptimizedImage.downsize(tempfile.path, tempfile.path, "80%", allow_animation: SiteSetting.allow_animated_thumbnails)
|
||||
OptimizedImage.downsize(tempfile.path, tempfile.path, "80%", filename: filename, allow_animation: allow_animation)
|
||||
attempt -= 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -108,7 +108,8 @@ class UserAvatarsController < ApplicationController
|
|||
upload,
|
||||
size,
|
||||
size,
|
||||
allow_animation: SiteSetting.allow_animated_avatars
|
||||
filename: upload.original_filename,
|
||||
allow_animation: SiteSetting.allow_animated_avatars,
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,13 @@ module Jobs
|
|||
|
||||
def create_thumbnails_for_avatar(upload, user)
|
||||
Discourse.avatar_sizes.each do |size|
|
||||
OptimizedImage.create_for(upload, size, size, allow_animation: SiteSetting.allow_animated_avatars)
|
||||
OptimizedImage.create_for(
|
||||
upload,
|
||||
size,
|
||||
size,
|
||||
filename: upload.original_filename,
|
||||
allow_animation: SiteSetting.allow_animated_avatars
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -152,7 +152,9 @@ class OptimizedImage < ActiveRecord::Base
|
|||
|
||||
def self.optimize(operation, from, to, dimensions, opts={})
|
||||
method_name = "#{operation}_instructions"
|
||||
method_name += "_animated" if !!opts[:allow_animation] && from =~ /\.GIF$/i
|
||||
if !!opts[:allow_animation] && (from =~ /\.GIF$/i || opts[:filename] =~ /\.GIF$/i)
|
||||
method_name += "_animated"
|
||||
end
|
||||
instructions = self.send(method_name.to_sym, from, to, dimensions, opts)
|
||||
convert_with(instructions, to)
|
||||
end
|
||||
|
|
|
@ -29,7 +29,15 @@ class Upload < ActiveRecord::Base
|
|||
|
||||
def create_thumbnail!(width, height)
|
||||
return unless SiteSetting.create_thumbnails?
|
||||
thumbnail = OptimizedImage.create_for(self, width, height, allow_animation: SiteSetting.allow_animated_thumbnails)
|
||||
|
||||
thumbnail = OptimizedImage.create_for(
|
||||
self,
|
||||
width,
|
||||
height,
|
||||
filename: self.original_filename,
|
||||
allow_animation: SiteSetting.allow_animated_thumbnails
|
||||
)
|
||||
|
||||
if thumbnail
|
||||
optimized_images << thumbnail
|
||||
self.width = width
|
||||
|
@ -95,7 +103,7 @@ class Upload < ActiveRecord::Base
|
|||
width, height = ImageSizer.resize(w, h, max_width: max_width, max_height: max_width)
|
||||
end
|
||||
|
||||
OptimizedImage.resize(file.path, file.path, width, height, allow_animation: allow_animation)
|
||||
OptimizedImage.resize(file.path, file.path, width, height, filename: filename, allow_animation: allow_animation)
|
||||
end
|
||||
|
||||
# optimize image
|
||||
|
|
Loading…
Reference in New Issue
Block a user