From 11172b7c2d4d359d0d1a69646f87ef9ab370bc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 27 Jul 2016 18:48:02 +0200 Subject: [PATCH] FIX: cropping GIF wasn't working --- app/models/optimized_image.rb | 11 +++++++++-- lib/image_sizer.rb | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index d228ce059..97989d60b 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -118,11 +118,11 @@ class OptimizedImage < ActiveRecord::Base def self.resize_instructions_animated(from, to, dimensions, opts={}) %W{ gifsicle - #{from} --colors=256 --resize-fit #{dimensions} --optimize=3 --output #{to} + #{from} } end @@ -142,7 +142,14 @@ class OptimizedImage < ActiveRecord::Base end def self.crop_instructions_animated(from, to, dimensions, opts={}) - resize_instructions_animated(from, to, dimensions, opts) + %W{ + gifsicle + --crop 0,0+#{dimensions} + --colors=256 + --optimize=3 + --output #{to} + #{from} + } end def self.downsize_instructions(from, to, dimensions, opts={}) diff --git a/lib/image_sizer.rb b/lib/image_sizer.rb index 3cf9f126f..ee368ce3d 100644 --- a/lib/image_sizer.rb +++ b/lib/image_sizer.rb @@ -28,7 +28,8 @@ module ImageSizer return [w.floor, h.floor] if w <= max_width && h <= max_height ratio = max_width / w - [max_width.floor, [max_height, (h * ratio)].min.floor] + + [[max_width, w].min.floor, [max_height, (h * ratio)].min.floor] end end