From 1c12dd529fad8888f2334962adc0736fd3756172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 10 Jul 2017 16:35:23 +0200 Subject: [PATCH] FIX: fix orientation even for small JPEGs --- lib/upload_creator.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb index 43ef92c27e1..656d74f90ef 100644 --- a/lib/upload_creator.rb +++ b/lib/upload_creator.rb @@ -46,6 +46,7 @@ class UploadCreator return @upload if is_still_too_big? + fix_orientation! if should_fix_orientation? crop! if should_crop? optimize! if should_optimize? end @@ -186,6 +187,18 @@ class UploadCreator @file.rewind end + def should_fix_orientation? + # orientation is between 1 and 8, 1 being the default + # cf. http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ + @image_info.orientation.to_i > 1 + end + + def fix_orientation! + OptimizedImage.ensure_safe_paths!(@file.path) + Discourse::Utils.execute_command('convert', @file.path, '-auto-orient', @file.path) + extract_image_info! + end + def should_crop? TYPES_TO_CROP.include?(@opts[:type]) end