From d541018bb25f641a0e73d4b7374d6f0a4e85dd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 9 Nov 2015 15:09:08 +0100 Subject: [PATCH] FIX: automagic image downsizing wasn't working for GIFs... --- app/controllers/uploads_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index d1251784ffd..ad5b551a051 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -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