Skip to content

Commit 22a33d3

Browse files
committed
Auto-orient images when determining dimensions
libvips and image magick handle image orientation correctly when creating thumbnails. Paperclip only parses the orientation header, but does not automatically apply when parsing geometry. Storing dimensions in the wrong orientation causes inline images to have an incorrect aspect ratio. REDMINE-20746
1 parent cf5c162 commit 22a33d3

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

app/models/pageflow/image_file.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def self.scale_down_to_cover(width, height)
8181

8282
def save_image_dimensions
8383
geo = Paperclip::Geometry.from_file(attachment.queued_for_write[:original])
84+
geo.auto_orient
85+
8486
self.width = geo.width
8587
self.height = geo.height
8688
rescue Paperclip::Errors::NotIdentifiedByImageMagickError

spec/fixtures/7x15_rotated.jpg

420 Bytes
Loading

spec/state_machines/pageflow/image_and_text_track_processing_state_machine_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ module Pageflow
3737
expect(file.reload.height).to eq(15)
3838
end
3939

40+
it 'auto orients image when saving width and heigh' do
41+
file = create(:image_file, :uploaded, file_name: '7x15_rotated.jpg')
42+
43+
file.process
44+
45+
expect(file.reload.width).to eq(15)
46+
expect(file.reload.height).to eq(7)
47+
end
48+
4049
it 'sets width and height to nil if image cannot be identified' do
4150
file = create(:image_file, :uploaded, file_name: 'broken.jpg')
4251

0 commit comments

Comments
 (0)