Skip to content

Commit

Permalink
Merge pull request #2113 from tf/auto-orient-images
Browse files Browse the repository at this point in the history
Auto-orient images when determining dimensions
  • Loading branch information
tf authored Jun 14, 2024
2 parents cf5c162 + 22a33d3 commit c2a7d3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/pageflow/image_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def self.scale_down_to_cover(width, height)

def save_image_dimensions
geo = Paperclip::Geometry.from_file(attachment.queued_for_write[:original])
geo.auto_orient

self.width = geo.width
self.height = geo.height
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
Expand Down
Binary file added spec/fixtures/7x15_rotated.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ module Pageflow
expect(file.reload.height).to eq(15)
end

it 'auto orients image when saving width and heigh' do
file = create(:image_file, :uploaded, file_name: '7x15_rotated.jpg')

file.process

expect(file.reload.width).to eq(15)
expect(file.reload.height).to eq(7)
end

it 'sets width and height to nil if image cannot be identified' do
file = create(:image_file, :uploaded, file_name: 'broken.jpg')

Expand Down

0 comments on commit c2a7d3d

Please sign in to comment.