mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 09:10:25 +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
5 changed files with 24 additions and 6 deletions
|
@ -67,9 +67,10 @@ class UploadsController < ApplicationController
|
||||||
|
|
||||||
# allow users to upload large images that will be automatically reduced to allowed size
|
# 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
|
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
|
attempt = 5
|
||||||
while attempt > 0 && File.size(tempfile.path) > SiteSetting.max_image_size_kb.kilobytes
|
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
|
attempt -= 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,7 +108,8 @@ class UserAvatarsController < ApplicationController
|
||||||
upload,
|
upload,
|
||||||
size,
|
size,
|
||||||
size,
|
size,
|
||||||
allow_animation: SiteSetting.allow_animated_avatars
|
filename: upload.original_filename,
|
||||||
|
allow_animation: SiteSetting.allow_animated_avatars,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,13 @@ module Jobs
|
||||||
|
|
||||||
def create_thumbnails_for_avatar(upload, user)
|
def create_thumbnails_for_avatar(upload, user)
|
||||||
Discourse.avatar_sizes.each do |size|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,9 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
|
|
||||||
def self.optimize(operation, from, to, dimensions, opts={})
|
def self.optimize(operation, from, to, dimensions, opts={})
|
||||||
method_name = "#{operation}_instructions"
|
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)
|
instructions = self.send(method_name.to_sym, from, to, dimensions, opts)
|
||||||
convert_with(instructions, to)
|
convert_with(instructions, to)
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,15 @@ class Upload < ActiveRecord::Base
|
||||||
|
|
||||||
def create_thumbnail!(width, height)
|
def create_thumbnail!(width, height)
|
||||||
return unless SiteSetting.create_thumbnails?
|
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
|
if thumbnail
|
||||||
optimized_images << thumbnail
|
optimized_images << thumbnail
|
||||||
self.width = width
|
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)
|
width, height = ImageSizer.resize(w, h, max_width: max_width, max_height: max_width)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# optimize image
|
# optimize image
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue