about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-07-30 14:39:06 +0200
committerThibaut Girka <thib@sitedethib.com>2018-07-30 14:39:06 +0200
commit5f1bdca4c8c3f34e0cc8f6ed3b6a264f42cc8ed2 (patch)
tree8727c7f3f289fa29051a31df67d6dc8d5c60e422 /lib
parentb02bfe86ce26ef001420841673257c9c5326b45c (diff)
parente23b26178a71f90d64fe2a3e9e4468f265ecc71c (diff)
Merge commit 'e23b26178a71f90d64fe2a3e9e4468f265ecc71c' into glitch-soc/merge-upstream
Merge upstream changes right before the public profile redesign.
Diffstat (limited to 'lib')
-rw-r--r--lib/paperclip/lazy_thumbnail.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/paperclip/lazy_thumbnail.rb b/lib/paperclip/lazy_thumbnail.rb
index aafa21343..ea675a5bf 100644
--- a/lib/paperclip/lazy_thumbnail.rb
+++ b/lib/paperclip/lazy_thumbnail.rb
@@ -5,8 +5,14 @@ module Paperclip
     def make
       return File.open(@file.path) unless needs_convert?
 
-      min_side = [@current_geometry.width, @current_geometry.height].min
-      options[:geometry] = "#{min_side.to_i}x#{min_side.to_i}#" if @target_geometry.square? && min_side < @target_geometry.width
+      if options[:geometry]
+        min_side = [@current_geometry.width, @current_geometry.height].min.to_i
+        options[:geometry] = "#{min_side}x#{min_side}#" if @target_geometry.square? && min_side < @target_geometry.width
+      elsif options[:pixels]
+        width  = Math.sqrt(options[:pixels] * (@current_geometry.width.to_f / @current_geometry.height.to_f)).round.to_i
+        height = Math.sqrt(options[:pixels] * (@current_geometry.height.to_f / @current_geometry.width.to_f)).round.to_i
+        options[:geometry] = "#{width}x#{height}>"
+      end
 
       Paperclip::Thumbnail.make(file, options, attachment)
     end
@@ -18,7 +24,8 @@ module Paperclip
     end
 
     def needs_different_geometry?
-      !@target_geometry.nil? && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height
+      (options[:geometry] && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height) ||
+        (options[:pixels] && @current_geometry.width * @current_geometry.height > options[:pixels])
     end
 
     def needs_different_format?