diff --git a/.gitignore b/.gitignore index 3e5e9e6..9b47b5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Gemfile.lock pkg/ +.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index d4020da..e994c5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/image_processing/vips.rb b/lib/image_processing/vips.rb index 90e7109..759b660 100644 --- a/lib/image_processing/vips.rb +++ b/lib/image_processing/vips.rb @@ -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) diff --git a/test/fixtures/exif_portrait.jpg b/test/fixtures/exif_portrait.jpg new file mode 100644 index 0000000..42ee096 Binary files /dev/null and b/test/fixtures/exif_portrait.jpg differ diff --git a/test/vips_test.rb b/test/vips_test.rb index c9279e9..bde706c 100644 --- a/test/vips_test.rb +++ b/test/vips_test.rb @@ -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 @@ -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 @@ -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