From 749b98175963ae4466250d83af556aa2f248e67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 25 Jul 2016 23:01:28 +0200 Subject: [PATCH] FEATURE: new 'convert_pasted_images_to_hq_jpg' site setting --- app/controllers/uploads_controller.rb | 9 +++++++++ config/locales/server.en.yml | 2 ++ config/site_settings.yml | 1 + 3 files changed, 12 insertions(+) diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 7eeca37d888..5a718bd09d9 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -70,6 +70,15 @@ class UploadsController < ApplicationController return { errors: I18n.t("upload.file_missing") } if tempfile.nil? + # convert pasted images to HQ jpegs + if filename == "blob.png" && SiteSetting.convert_pasted_images_to_hq_jpg + filename = "blob.jpg" + jpeg_path = "#{File.dirname(tempfile.path)}/#{filename}" + content_type = "image/jpeg" + `convert #{tempfile.path} -quality 95 #{jpeg_path}` + tempfile = File.open(jpeg_path) + end + # allow users to upload large images that will be automatically reduced to allowed size max_image_size_kb = SiteSetting.max_image_size_kb.kilobytes if max_image_size_kb > 0 && FileHelper.is_image?(filename) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 4378f5f6dde..6bd5dd295a5 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1069,6 +1069,8 @@ en: allow_all_attachments_for_group_messages: "Allow all email attachments for group messages." + convert_pasted_images_to_hq_jpg: "Convert pasted images to high-quality JPG files." + enable_flash_video_onebox: "Enable embedding of swf and flv (Adobe Flash) links in oneboxes. WARNING: may introduce security risks." default_invitee_trust_level: "Default trust level (0-4) for invited users." diff --git a/config/site_settings.yml b/config/site_settings.yml index 6f41f3c4256..35bf337a935 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -717,6 +717,7 @@ files: shadowed_by_global: true default_opengraph_image_url: '' allow_all_attachments_for_group_messages: false + convert_pasted_images_to_hq_jpg: true trust: default_trust_level: