Skip to content

Commit

Permalink
Fix autorotation issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 6, 2020
1 parent 88c272f commit 83e7d95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/vips/thumbnail/resizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ module Thumbnail
class Resizer
def initialize(input_path = nil, **options, &block)
@input_path = input_path
@options = options

@block = block || lambda do
Vips::Image.new_from_file(@input_path, **options).tap do |image|
image.autorot if image.respond_to?(:autorot)
end
end
@block = block || self.method(:load)

@input_image = nil
end
Expand Down Expand Up @@ -78,6 +75,16 @@ def resize_to_fit(output_size)

private

def load
image = Vips::Image.new_from_file(@input_path, **@options)

if image.respond_to?(:autorot)
image = image.autorot
end

return image
end

def fit(image, width, height)
x_scale = Rational(width, image.width)
y_scale = Rational(height, image.height)
Expand Down
Binary file added spec/vips/thumbnail/IMG_8537-rotated.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions spec/vips/thumbnail/resizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
let(:sample_path) {File.expand_path('IMG_8537.jpg', __dir__)}
subject{described_class.new(sample_path)}

describe '#load' do
let(:sample_path) {File.expand_path('IMG_8537-rotated.jpg', __dir__)}

it "autorotates the image" do
expect(subject.input_image.size).to be == [2448, 3264]
output_image = subject.resize_to_fill([400, 400])

# output_image.write_to_file("resized.jpg")
end
end

describe '#resize_to_fill' do
it "should load image with correct size" do
expect(subject.input_image).to_not be_nil
Expand Down

0 comments on commit 83e7d95

Please sign in to comment.