diff --git a/app/models/pageflow/image_file.rb b/app/models/pageflow/image_file.rb index b49e419f7b..d6f396eb50 100644 --- a/app/models/pageflow/image_file.rb +++ b/app/models/pageflow/image_file.rb @@ -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 diff --git a/spec/fixtures/7x15_rotated.jpg b/spec/fixtures/7x15_rotated.jpg new file mode 100644 index 0000000000..99c7d5d158 Binary files /dev/null and b/spec/fixtures/7x15_rotated.jpg differ diff --git a/spec/state_machines/pageflow/image_and_text_track_processing_state_machine_spec.rb b/spec/state_machines/pageflow/image_and_text_track_processing_state_machine_spec.rb index 3b0b5d4ca4..32aba6f1f5 100644 --- a/spec/state_machines/pageflow/image_and_text_track_processing_state_machine_spec.rb +++ b/spec/state_machines/pageflow/image_and_text_track_processing_state_machine_spec.rb @@ -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')