FIX: don't automagically downsize uploaded images that are larger than 10MB
FIX: don't optimize GIFs since ImageOption was disabled for GIFs (too slow)
This commit is contained in:
parent
2561b5f304
commit
09bfe49254
|
@ -71,11 +71,15 @@ class UploadsController < ApplicationController
|
|||
|
||||
return { errors: I18n.t("upload.file_missing") } if tempfile.nil?
|
||||
|
||||
# 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 users to upload (not that) large images that will be automatically reduced to allowed size
|
||||
uploaded_size = File.size(tempfile.path)
|
||||
if SiteSetting.max_image_size_kb > 0 && FileHelper.is_image?(filename) && uploaded_size > 0 && uploaded_size < 10.megabytes
|
||||
attempt = 2
|
||||
allow_animation = type == "avatar" ? SiteSetting.allow_animated_avatars : SiteSetting.allow_animated_thumbnails
|
||||
while attempt > 0 && File.size(tempfile.path) > SiteSetting.max_image_size_kb.kilobytes
|
||||
while attempt > 0
|
||||
downsized_size = File.size(tempfile.path)
|
||||
break if downsized_size > uploaded_size
|
||||
break if downsized_size < SiteSetting.max_image_size_kb.kilobytes
|
||||
image_info = FastImage.new(tempfile.path) rescue nil
|
||||
w, h = *(image_info.try(:size) || [0, 0])
|
||||
break if w == 0 || h == 0
|
||||
|
|
|
@ -107,12 +107,12 @@ class Upload < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# optimize image
|
||||
ImageOptim.new.optimize_image!(file.path) rescue nil
|
||||
|
||||
# correct size so it displays the optimized image size which is the only
|
||||
# one that is stored
|
||||
filesize = File.size(file.path)
|
||||
# optimize image (but not for GIFs)
|
||||
if filename !~ /\.GIF$/i
|
||||
ImageOptim.new.optimize_image!(file.path) rescue nil
|
||||
# update the file size
|
||||
filesize = File.size(file.path)
|
||||
end
|
||||
end
|
||||
|
||||
# compute the sha of the file
|
||||
|
|
Loading…
Reference in New Issue