mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
Retry PNG to JPG conversion with debug enabled on failure
This commit is contained in:
parent
9472821331
commit
b47b378cb6
|
@ -134,15 +134,13 @@ class UploadCreator
|
||||||
jpeg_tempfile = Tempfile.new(["image", ".jpg"])
|
jpeg_tempfile = Tempfile.new(["image", ".jpg"])
|
||||||
|
|
||||||
OptimizedImage.ensure_safe_paths!(@file.path, jpeg_tempfile.path)
|
OptimizedImage.ensure_safe_paths!(@file.path, jpeg_tempfile.path)
|
||||||
Discourse::Utils.execute_command(
|
|
||||||
'convert', @file.path,
|
begin
|
||||||
'-auto-orient',
|
execute_convert(@file, jpeg_tempfile)
|
||||||
'-background', 'white',
|
rescue
|
||||||
'-interlace', 'none',
|
# retry with debugging enabled
|
||||||
'-flatten',
|
execute_convert(@file, jpeg_tempfile, true)
|
||||||
'-quality', SiteSetting.png_to_jpg_quality.to_s,
|
end
|
||||||
jpeg_tempfile.path
|
|
||||||
)
|
|
||||||
|
|
||||||
# keep the JPEG if it's at least 15% smaller
|
# keep the JPEG if it's at least 15% smaller
|
||||||
if File.size(jpeg_tempfile.path) < filesize * 0.85
|
if File.size(jpeg_tempfile.path) < filesize * 0.85
|
||||||
|
@ -155,6 +153,19 @@ class UploadCreator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def execute_convert(input_file, output_file, debug = false)
|
||||||
|
command = ['convert', input_file.path,
|
||||||
|
'-auto-orient',
|
||||||
|
'-background', 'white',
|
||||||
|
'-interlace', 'none',
|
||||||
|
'-flatten',
|
||||||
|
'-quality', SiteSetting.png_to_jpg_quality.to_s]
|
||||||
|
command << '-debug' << 'all' if debug
|
||||||
|
command << output_file.path
|
||||||
|
|
||||||
|
Discourse::Utils.execute_command(*command, failure_message: "failed to convert png to jpg")
|
||||||
|
end
|
||||||
|
|
||||||
def should_downsize?
|
def should_downsize?
|
||||||
max_image_size > 0 && filesize >= max_image_size
|
max_image_size > 0 && filesize >= max_image_size
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user