Skip to content

A platform for community discussion. Free, open, simple.

DEV: pasted images should respect png to jpg site setting (#40872)

David Battersbye6fcdc90f116
diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb
index ded3944d7ca..65c7d7f32ad 100644
--- a/lib/upload_creator.rb
+++ b/lib/upload_creator.rb
@@ -321,8 +321,8 @@ class UploadCreator
def convert_png_to_jpeg?
return false unless @image_info.type == :png
- return true if @opts[:pasted]
return false if SiteSetting.ImageQuality.png_to_jpg_quality == 100
+ return true if @opts[:pasted]
pixels > MIN_PIXELS_TO_CONVERT_TO_JPEG
end
diff --git a/spec/lib/upload_creator_spec.rb b/spec/lib/upload_creator_spec.rb
index d4b8dccf8cc..88b17d0a2fd 100644
--- a/spec/lib/upload_creator_spec.rb
+++ b/spec/lib/upload_creator_spec.rb
@@ -266,6 +266,20 @@ RSpec.describe UploadCreator do
expect(File.extname(upload.url)).to eq(".png")
expect(upload.original_filename).to eq("large_and_unoptimized.png")
end
+
+ it "should not convert pasted images to jpeg when png_to_jpg_quality is 100" do
+ upload =
+ UploadCreator.new(
+ large_file,
+ large_filename,
+ pasted: true,
+ force_optimize: true,
+ ).create_for(user.id)
+
+ expect(upload.extension).to eq("png")
+ expect(File.extname(upload.url)).to eq(".png")
+ expect(upload.original_filename).to eq("large_and_unoptimized.png")
+ end
end
it "should not convert animated WEBP images" do