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/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..558202e3e 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) 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 diff --git a/spec/fixtures/autumn_1440x960.heic b/spec/fixtures/autumn_1440x960.heic new file mode 100644 index 000000000..00cc549c0 Binary files /dev/null and b/spec/fixtures/autumn_1440x960.heic differ diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 0b4996506..34c24b936 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -17,12 +17,13 @@ describe Photo, :type => :model do @aspect = @user.aspects.first @fixture_filename = 'button.png' + @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) @fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml') - @photo = @user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id) - @photo2 = @user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id) - @saved_photo = @user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id) + @photo = @user.build_post(:photo, user_file: File.open(@fixture_name), to: @aspect.id) + @photo2 = @user.build_post(:photo, user_file: File.open(@fixture_name), to: @aspect.id) + @saved_photo = @user.build_post(:photo, user_file: File.open(@fixture_name), to: @aspect.id) @saved_photo.save end @@ -90,7 +91,7 @@ describe Photo, :type => :model do @photo.update_remote_path expect(@photo.remote_photo_path).to include("http") - expect(@photo.remote_photo_name).to include(".png") + expect(@photo.remote_photo_name).to include(".webp") end end @@ -182,7 +183,15 @@ describe Photo, :type => :model do @photo.unprocessed_image.store! file }.to raise_error CarrierWave::IntegrityError end + end + describe "converting files" do + it "convert to webp" do + with_carrierwave_processing do + @photo.unprocessed_image.store! File.open(@fixture_name) + end + expect(@photo.remote_photo_name).to include(".webp") + end end describe "remote photos" do