Skip to content

Commit

Permalink
allow resize_to_fill to skip cropping janko#74
Browse files Browse the repository at this point in the history
  • Loading branch information
astevenson committed Nov 20, 2020
1 parent bd2f826 commit 35d3dc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/image_processing/mini_magick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def resize_to_fit(width, height, **options)
end

# Resizes the image to fill the specified dimensions, applying any
# necessary cropping.
def resize_to_fill(width, height, gravity: "Center", **options)
# necessary cropping. Passing crop: false will treat each
# dimmension as a minimum and overflow as needed.
def resize_to_fill(width, height, gravity: "Center", crop: true, **options)
thumbnail("#{width}x#{height}^", **options)
return magick unless crop
magick.gravity gravity
magick.background color(:transparent)
magick.extent "#{width}x#{height}"
Expand Down
4 changes: 4 additions & 0 deletions test/mini_magick_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@
assert_dimensions [1000, 1000], @pipeline.resize_to_fill!(1000, 1000)
end

it "will skip cropping if asked" do
assert_dimensions [400, 533], @pipeline.resize_to_fill!(400, 400, crop: false)
end

it "produces correct image" do
expected = fixture_image("fill.jpg")
assert_similar expected, @pipeline.resize_to_fill!(400, 400)
Expand Down

0 comments on commit 35d3dc2

Please sign in to comment.