diff --git a/app/assets/javascripts/helpers/post_photo_uploader.es6 b/app/assets/javascripts/helpers/post_photo_uploader.es6 index ba94ec5ed6b..23140c5057e 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/heic, image/webp", + allowedExtensions: ["jpg", "jpeg", "png", "gif", "heic", "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 cc70ba1c168..d3267e40311 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/heic, image/webp", + allowedExtensions: ["png", "jpg", "jpeg", "gif", "heic", "webp"], sizeLimit: 4194304 }, request: { diff --git a/app/uploaders/processed_image.rb b/app/uploaders/processed_image.rb index 79b61b9c7ab..0c725a10d53 100644 --- a/app/uploaders/processed_image.rb +++ b/app/uploaders/processed_image.rb @@ -12,7 +12,7 @@ def store_dir end def extension_allowlist - %w[jpg jpeg png gif] + %w[jpg jpeg png gif heic webp] end def filename diff --git a/app/uploaders/unprocessed_image.rb b/app/uploaders/unprocessed_image.rb index 6dad5f602b6..ed9d9c1433a 100644 --- a/app/uploaders/unprocessed_image.rb +++ b/app/uploaders/unprocessed_image.rb @@ -18,24 +18,43 @@ def store_dir end def extension_allowlist - %w[jpg jpeg png gif] + %w[jpg jpeg png gif heic 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) + !extname.eql?(".webp") 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? + + convert_to_jpeg(img) if needs_converting? img end end + # @param [ImageProcessing::Builder] img + def convert_to_jpeg(img) + img.format("webp") + end + version :thumb_small version :thumb_medium version :thumb_large diff --git a/spec/fixtures/autumn_1440x960.heic b/spec/fixtures/autumn_1440x960.heic new file mode 100644 index 00000000000..00cc549c037 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 0b4996506a1..652713a5ff2 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -17,12 +17,16 @@ def with_carrierwave_processing(&block) @aspect = @user.aspects.first @fixture_filename = 'button.png' + @heic_filename = "autumn_1440x960.heic" + @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) + @heic_file_name = File.join(File.dirname(__FILE__), "..", "fixtures", @heic_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) + @heic_photo = @user.build_post(:photo, user_file: File.open(@heic_file_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 @@ -182,7 +186,15 @@ def image_from(photo) @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 + @heic_photo.unprocessed_image.store! File.open(@heic_file_name) + end + expect(@heic_photo.remote_photo_name).to include(".webp") + end end describe "remote photos" do