aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-01-02 07:19:39 -0500
committerGeorge Claghorn <george@basecamp.com>2018-01-02 07:20:23 -0500
commit921b877c2fd51cc0abdcf0ef6ca3528808047056 (patch)
treef9fe7ee526880d37c99130c57da9bc3e9ca844c2 /activestorage
parent13afd2cfdc8c83037b0739ca8a072ac4badb8afd (diff)
downloadrails-921b877c2fd51cc0abdcf0ef6ca3528808047056.tar.gz
rails-921b877c2fd51cc0abdcf0ef6ca3528808047056.tar.bz2
rails-921b877c2fd51cc0abdcf0ef6ca3528808047056.zip
Restore support for the -layers transformation
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/app/models/active_storage/variation.rb28
-rw-r--r--activestorage/test/fixtures/files/image.gifbin0 -> 2032 bytes
-rw-r--r--activestorage/test/models/variant_test.rb8
3 files changed, 22 insertions, 14 deletions
diff --git a/activestorage/app/models/active_storage/variation.rb b/activestorage/app/models/active_storage/variation.rb
index 2b599a4710..0046e6870b 100644
--- a/activestorage/app/models/active_storage/variation.rb
+++ b/activestorage/app/models/active_storage/variation.rb
@@ -46,15 +46,15 @@ class ActiveStorage::Variation
# 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.
def transform(image)
- transformations.each do |(transformation_method, transformation_argument)|
- if transformation_method.to_s == "combine_options"
- image.combine_options do |combination|
- transformation_argument.each do |(method, argument)|
- pass_transform_argument(combination, method, argument)
+ transformations.each do |name, argument_or_subtransformations|
+ image.mogrify do |command|
+ if name.to_s == "combine_options"
+ argument_or_subtransformations.each do |subtransformation_name, subtransformation_argument|
+ pass_transform_argument(command, subtransformation_name, subtransformation_argument)
end
+ else
+ pass_transform_argument(command, name, argument_or_subtransformations)
end
- else
- pass_transform_argument(image, transformation_method, transformation_argument)
end
end
end
@@ -65,15 +65,15 @@ class ActiveStorage::Variation
end
private
- def eligible_argument?(argument)
- argument.present? && argument != true
- end
-
- def pass_transform_argument(instance, method, argument)
+ def pass_transform_argument(command, method, argument)
if eligible_argument?(argument)
- instance.public_send(method, argument)
+ command.public_send(method, argument)
else
- instance.public_send(method)
+ command.public_send(method)
end
end
+
+ def eligible_argument?(argument)
+ argument.present? && argument != true
+ end
end
diff --git a/activestorage/test/fixtures/files/image.gif b/activestorage/test/fixtures/files/image.gif
new file mode 100644
index 0000000000..90c05f671c
--- /dev/null
+++ b/activestorage/test/fixtures/files/image.gif
Binary files differ
diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb
index 2a96dfb142..7157bfac3a 100644
--- a/activestorage/test/models/variant_test.rb
+++ b/activestorage/test/models/variant_test.rb
@@ -50,6 +50,14 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
assert_equal 20, image.height
end
+ test "optimized variation of GIF blob" do
+ blob = create_file_blob(filename: "image.gif", content_type: "image/gif")
+
+ assert_nothing_raised do
+ blob.variant(layers: "Optimize").processed
+ end
+ end
+
test "variation of invariable blob" do
assert_raises ActiveStorage::Blob::InvariableError do
create_file_blob(filename: "report.pdf", content_type: "application/pdf").variant(resize: "100x100")