Skip to content

Commit

Permalink
Fix bug in resize_to_cover where the image is provided as a string (#136
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brendon authored Feb 8, 2025
1 parent 264b0b1 commit 8490530
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
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

0 comments on commit 8490530

Please sign in to comment.