FIX: fix orientation even for small JPEGs

This commit is contained in:
Régis Hanol 2017-07-10 16:35:23 +02:00
parent c66b9dcdbd
commit 1c12dd529f

View File

@ -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