diff options
author | George Claghorn <george@basecamp.com> | 2017-12-11 13:28:05 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2017-12-11 13:28:05 -0500 |
commit | a80f81af055f02bf4625c90470aa90441cf6fc24 (patch) | |
tree | 08deddeb9d03aea2fc7e72d0382060916d5b4413 /activestorage/app | |
parent | 4edce566ad13d54c86637caf56750df0d6dc7b1a (diff) | |
download | rails-a80f81af055f02bf4625c90470aa90441cf6fc24.tar.gz rails-a80f81af055f02bf4625c90470aa90441cf6fc24.tar.bz2 rails-a80f81af055f02bf4625c90470aa90441cf6fc24.zip |
Invoke mogrify once when transforming an image
Execute a single mogrify command with multiple options rather than one command per option. Permit the use of all mogrify options, not just the ones that fall through to MiniMagick::Image#method_missing.
Diffstat (limited to 'activestorage/app')
-rw-r--r-- | activestorage/app/models/active_storage/variation.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/activestorage/app/models/active_storage/variation.rb b/activestorage/app/models/active_storage/variation.rb index 13bad87cac..6a8825f1a8 100644 --- a/activestorage/app/models/active_storage/variation.rb +++ b/activestorage/app/models/active_storage/variation.rb @@ -44,13 +44,15 @@ class ActiveStorage::Variation end # Accepts an open MiniMagick image instance, like what's returned by <tt>MiniMagick::Image.read(io)</tt>, - # and performs the +transformations+ against it. The transformed image instance is then returned. + # and performs the +transformations+ against it. def transform(image) - transformations.each do |(method, argument)| - if eligible_argument?(argument) - image.public_send(method, argument) - else - image.public_send(method) + image.mogrify do |command| + transformations.each do |method, argument| + if eligible_argument?(argument) + command.public_send(method, argument) + else + command.public_send(method) + end end end end |