Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow resize_to_fill to skip cropping #74 #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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