From b84f2018d57844b5cf8814ac206441310245be8e Mon Sep 17 00:00:00 2001
From: Marek Lipka <mlipka@efigence.com>
Date: Wed, 4 Sep 2019 20:43:17 +0200
Subject: [PATCH] Prevent stripping color profiles from JPEGs

---
 app/models/concerns/account_avatar.rb | 2 +-
 app/models/concerns/account_header.rb | 2 +-
 app/models/custom_emoji.rb            | 2 +-
 app/models/media_attachment.rb        | 2 +-
 app/models/preview_card.rb            | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/app/models/concerns/account_avatar.rb b/app/models/concerns/account_avatar.rb
index 2d5ebfca35..753531a78f 100644
--- a/app/models/concerns/account_avatar.rb
+++ b/app/models/concerns/account_avatar.rb
@@ -18,7 +18,7 @@ module AccountAvatar
 
   included do
     # Avatar upload
-    has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-strip' }, processors: [:lazy_thumbnail]
+    has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '+profile exif' }, processors: [:lazy_thumbnail]
     validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
     validates_attachment_size :avatar, less_than: LIMIT
     remotable_attachment :avatar, LIMIT
diff --git a/app/models/concerns/account_header.rb b/app/models/concerns/account_header.rb
index 067e166eb6..aed2baddc2 100644
--- a/app/models/concerns/account_header.rb
+++ b/app/models/concerns/account_header.rb
@@ -19,7 +19,7 @@ module AccountHeader
 
   included do
     # Header upload
-    has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-strip' }, processors: [:lazy_thumbnail]
+    has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '+profile exif' }, processors: [:lazy_thumbnail]
     validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
     validates_attachment_size :header, less_than: LIMIT
     remotable_attachment :header, LIMIT
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb
index 0dacaf654b..b42fac1044 100644
--- a/app/models/custom_emoji.rb
+++ b/app/models/custom_emoji.rb
@@ -33,7 +33,7 @@ class CustomEmoji < ApplicationRecord
   belongs_to :category, class_name: 'CustomEmojiCategory', optional: true
   has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode
 
-  has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } }
+  has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce +profile exif' } }
 
   before_validation :downcase_domain
 
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 6468d104d2..b2602860c3 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -132,7 +132,7 @@ class MediaAttachment < ApplicationRecord
   has_attached_file :file,
                     styles: ->(f) { file_styles f },
                     processors: ->(f) { file_processors f },
-                    convert_options: { all: '-quality 90 -strip +set modify-date +set create-date' }
+                    convert_options: { all: '-quality 90 +profile exif +set modify-date +set create-date' }
 
   validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES
   validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :larger_media_format?
diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb
index 4e89fbf851..107ba433c3 100644
--- a/app/models/preview_card.rb
+++ b/app/models/preview_card.rb
@@ -34,7 +34,7 @@ class PreviewCard < ApplicationRecord
 
   has_and_belongs_to_many :statuses
 
-  has_attached_file :image, styles: ->(f) { image_styles(f) }, convert_options: { all: '-quality 80 -strip' }
+  has_attached_file :image, styles: ->(f) { image_styles(f) }, convert_options: { all: '-quality 80 +profile exif' }
 
   include Attachmentable
 
@@ -66,7 +66,7 @@ class PreviewCard < ApplicationRecord
         original: {
           geometry: '400x400>',
           file_geometry_parser: FastGeometryParser,
-          convert_options: '-coalesce -strip',
+          convert_options: '-coalesce +profile exif',
         },
       }
 
-- 
GitLab