Skip to content

Commit 8490530

Browse files
authored
Fix bug in resize_to_cover where the image is provided as a string (#136)
1 parent 264b0b1 commit 8490530

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Gemfile.lock
22
pkg/
3+
.DS_Store

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
3+
* Fix `#resize_to_cover` when dealing with EXIF orientated images (@brendon)
4+
15
## 1.13.0 (2024-07-24)
26

37
* [minimagick] Use `-append` when calling `#append` with no arguments (@janko)

lib/image_processing/vips.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def resize_and_pad(width, height, gravity: "centre", extend: nil, background: ni
9393
# Resizes the image to cover the specified dimensions, without
9494
# cropping the excess.
9595
def resize_to_cover(width, height, **options)
96-
image = self.image.is_a?(String) ? ::Vips::Image.new_from_file(self.image) : self.image
96+
image = self.image.is_a?(String) ? self.class.load_image(self.image) : self.image
9797

9898
image_ratio = Rational(image.width, image.height)
9999
thumbnail_ratio = Rational(width, height)

test/fixtures/exif_portrait.jpg

8.37 MB
Loading

test/vips_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@portrait = fixture_image("portrait.jpg")
88
@landscape = fixture_image("landscape.jpg")
99
@square = fixture_image("square.jpg")
10+
@exif_portrait = fixture_image("exif_portrait.jpg")
1011
end
1112

1213
it "applies vips operations" do
@@ -328,6 +329,7 @@
328329
@portrait_pipeline = ImageProcessing::Vips.source(@portrait)
329330
@landscape_pipeline = ImageProcessing::Vips.source(@landscape)
330331
@square_pipeline = ImageProcessing::Vips.source(@square)
332+
@exif_portrait_pipeline = ImageProcessing::Vips.source(@exif_portrait)
331333
end
332334

333335
it "resizes the portrait image to fill out the given landscape dimensions" do
@@ -387,6 +389,10 @@
387389
sharpened = @portrait_pipeline.resize_to_cover(400, 400).call(save: false)
388390
assert_equal :uchar, sharpened.format
389391
end
392+
393+
it "works correctly with EXIF orientation" do
394+
assert_dimensions [300, 617], @exif_portrait_pipeline.resize_to_cover!(300, 200)
395+
end
390396
end
391397

392398
describe "#rotate" do

0 commit comments

Comments
 (0)