Skip to content

Fix bug in resize_to_cover where the image is provided as a string #136

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

Merged
merged 4 commits into from
Feb 8, 2025
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Gemfile.lock
pkg/
.DS_Store
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

* Fix `#resize_to_cover` when dealing with EXIF orientated images (@brendon)

## 1.13.0 (2024-07-24)

* [minimagick] Use `-append` when calling `#append` with no arguments (@janko)
Expand Down
2 changes: 1 addition & 1 deletion lib/image_processing/vips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def resize_and_pad(width, height, gravity: "centre", extend: nil, background: ni
# Resizes the image to cover the specified dimensions, without
# cropping the excess.
def resize_to_cover(width, height, **options)
image = self.image.is_a?(String) ? ::Vips::Image.new_from_file(self.image) : self.image
image = self.image.is_a?(String) ? self.class.load_image(self.image) : self.image

image_ratio = Rational(image.width, image.height)
thumbnail_ratio = Rational(width, height)
Expand Down
Binary file added test/fixtures/exif_portrait.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/vips_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@portrait = fixture_image("portrait.jpg")
@landscape = fixture_image("landscape.jpg")
@square = fixture_image("square.jpg")
@exif_portrait = fixture_image("exif_portrait.jpg")
end

it "applies vips operations" do
Expand Down Expand Up @@ -328,6 +329,7 @@
@portrait_pipeline = ImageProcessing::Vips.source(@portrait)
@landscape_pipeline = ImageProcessing::Vips.source(@landscape)
@square_pipeline = ImageProcessing::Vips.source(@square)
@exif_portrait_pipeline = ImageProcessing::Vips.source(@exif_portrait)
end

it "resizes the portrait image to fill out the given landscape dimensions" do
Expand Down Expand Up @@ -387,6 +389,10 @@
sharpened = @portrait_pipeline.resize_to_cover(400, 400).call(save: false)
assert_equal :uchar, sharpened.format
end

it "works correctly with EXIF orientation" do
assert_dimensions [300, 617], @exif_portrait_pipeline.resize_to_cover!(300, 200)
end
end

describe "#rotate" do
Expand Down
Loading