diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-16 05:46:18 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-16 05:48:03 +0300 |
commit | d0af34c0790e13eef187813d12f35ffe6f11b373 (patch) | |
tree | c91b1598053f8692aaea893ba7b3b36215ede80b /app | |
parent | 5669ba6b48f2488e394789bc6fb8504358e966b7 (diff) | |
parent | f995e6af0d02e9c085c2237f44ec36234ac0ed6e (diff) |
Merge pull request #8358 from tclaus/supporting_heic_images
Using webp as storage format for images
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/helpers/post_photo_uploader.es6 | 4 | ||||
-rw-r--r-- | app/assets/javascripts/mobile/mobile_profile_photo_uploader.js | 4 | ||||
-rw-r--r-- | app/models/photo.rb | 2 | ||||
-rw-r--r-- | app/services/import_service.rb | 1 | ||||
-rw-r--r-- | app/uploaders/processed_image.rb | 2 | ||||
-rw-r--r-- | app/uploaders/unprocessed_image.rb | 22 |
6 files changed, 25 insertions, 10 deletions
diff --git a/app/assets/javascripts/helpers/post_photo_uploader.es6 b/app/assets/javascripts/helpers/post_photo_uploader.es6 index ba94ec5ed..8f1f5695b 100644 --- a/app/assets/javascripts/helpers/post_photo_uploader.es6 +++ b/app/assets/javascripts/helpers/post_photo_uploader.es6 @@ -59,8 +59,8 @@ Diaspora.PostPhotoUploader = class { promptForName: true }, validation: { - acceptFiles: "image/png, image/jpeg, image/gif", - allowedExtensions: ["jpg", "jpeg", "png", "gif"], + acceptFiles: "image/png, image/jpeg, image/gif, image/webp", + allowedExtensions: ["jpg", "jpeg", "png", "gif", "webp"], sizeLimit: (window.Promise && qq.supportedFeatures.scaling ? null : this.sizeLimit) }, messages: { diff --git a/app/assets/javascripts/mobile/mobile_profile_photo_uploader.js b/app/assets/javascripts/mobile/mobile_profile_photo_uploader.js index cc70ba1c1..f3a5a9c08 100644 --- a/app/assets/javascripts/mobile/mobile_profile_photo_uploader.js +++ b/app/assets/javascripts/mobile/mobile_profile_photo_uploader.js @@ -11,8 +11,8 @@ Diaspora.ProfilePhotoUploader.prototype = { new qq.FineUploaderBasic({ element: document.getElementById("file-upload"), validation: { - acceptFiles: "image/png, image/jpeg, image/gif", - allowedExtensions: ["jpg", "jpeg", "png"], + acceptFiles: "image/png, image/jpeg, image/gif, image/webp", + allowedExtensions: ["png", "jpg", "jpeg", "gif", "webp"], sizeLimit: 4194304 }, request: { diff --git a/app/models/photo.rb b/app/models/photo.rb index 0a77df62a..e9fbe5d20 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -38,6 +38,7 @@ class Photo < ApplicationRecord mount_uploader :processed_image, ProcessedImage mount_uploader :unprocessed_image, UnprocessedImage + attr_accessor :keep_original_format belongs_to :status_message, foreign_key: :status_message_guid, primary_key: :guid, optional: true validates_associated :status_message @@ -50,7 +51,6 @@ class Photo < ApplicationRecord after_commit on: :create do queue_processing_job if author.local? - end scope :on_statuses, ->(post_guids) { diff --git a/app/services/import_service.rb b/app/services/import_service.rb index cb6d02e3b..89e107452 100644 --- a/app/services/import_service.rb +++ b/app/services/import_service.rb @@ -74,6 +74,7 @@ class ImportService def store_and_process_photo(photo, uploaded_file, random_string) File.open(uploaded_file) do |file| photo.random_string = random_string + photo.keep_original_format = true photo.unprocessed_image.store! file photo.update_remote_path photo.save(touch: false) diff --git a/app/uploaders/processed_image.rb b/app/uploaders/processed_image.rb index 79b61b9c7..5dfa6e5f0 100644 --- a/app/uploaders/processed_image.rb +++ b/app/uploaders/processed_image.rb @@ -12,7 +12,7 @@ class ProcessedImage < CarrierWave::Uploader::Base end def extension_allowlist - %w[jpg jpeg png gif] + %w[jpg jpeg png gif webp] end def filename diff --git a/app/uploaders/unprocessed_image.rb b/app/uploaders/unprocessed_image.rb index 6dad5f602..a653aa34f 100644 --- a/app/uploaders/unprocessed_image.rb +++ b/app/uploaders/unprocessed_image.rb @@ -18,20 +18,34 @@ class UnprocessedImage < CarrierWave::Uploader::Base end def extension_allowlist - %w[jpg jpeg png gif] + %w[jpg jpeg png gif webp] end def filename - model.random_string + File.extname(@filename) if @filename + model.random_string + extension if @filename + end + + def extension + needs_converting? ? ".webp" : File.extname(@filename) + end + + def needs_converting? + extname = File.extname(@filename) + %w[.webp .gif].exclude?(extname) && !model.keep_original_format end process :basic_process def basic_process manipulate! do |img| - img.auto_orient - img.strip if strip_exif + img.combine_options do |i| + i.auto_orient + i.strip if strip_exif + end + img = yield(img) if block_given? + + img.format("webp") if needs_converting? img end end |