FIX: automagic image downsizing wasn't working for GIFs...
This commit is contained in:
parent
448a1413d3
commit
d541018bb2
|
@ -67,10 +67,14 @@ 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
|
||||
attempt = 2
|
||||
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%", filename: filename, allow_animation: allow_animation)
|
||||
image_info = FastImage.new(tempfile.path) rescue nil
|
||||
w, h = *(image_info.try(:size) || [0, 0])
|
||||
break if w == 0 || h == 0
|
||||
dimensions = "#{(w * 0.8).floor}x#{(h * 0.8).floor}"
|
||||
OptimizedImage.downsize(tempfile.path, tempfile.path, dimensions, filename: filename, allow_animation: allow_animation)
|
||||
attempt -= 1
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue