Skip to content

Commit

Permalink
Restore support for the -layers transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeclaghorn committed Jan 2, 2018
1 parent 13afd2c commit 921b877
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
28 changes: 14 additions & 14 deletions activestorage/app/models/active_storage/variation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def initialize(transformations)
# 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
Expand All @@ -65,15 +65,15 @@ def key
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
Binary file added activestorage/test/fixtures/files/image.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions activestorage/test/models/variant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 921b877

Please sign in to comment.