FIX - don't attempt to optimized animated images (#11031)

* FIX - don't attempt to optimized animated images

* ensure_safe_paths before calling ImageMagick
This commit is contained in:
jbrw
2020-10-26 15:10:19 -04:00
committed by GitHub
parent d9a5d563cf
commit aeb24bd4b5
3 changed files with 52 additions and 10 deletions

View File

@@ -126,7 +126,7 @@ class UploadCreator
if is_image
@upload.thumbnail_width, @upload.thumbnail_height = ImageSizer.resize(*@image_info.size)
@upload.width, @upload.height = @image_info.size
@upload.animated = FastImage.animated?(@file)
@upload.animated = animated?(@file)
end
add_metadata!
@@ -177,6 +177,25 @@ class UploadCreator
end
end
def animated?(file)
OptimizedImage.ensure_safe_paths!(file.path)
# TODO - find out why:
# FastImage.animated?(@file)
# doesn't seem to identify all animated gifs
@frame_count ||= begin
command = [
"identify",
"-format", "%n\\n",
file.path
]
frames = Discourse::Utils.execute_command(*command).to_i rescue 1
end
@frame_count > 1
end
MIN_PIXELS_TO_CONVERT_TO_JPEG ||= 1280 * 720
def convert_png_to_jpeg?
@@ -267,6 +286,8 @@ class UploadCreator
end
def should_alter_quality?
return false if animated?(@file)
@upload.target_image_quality(@file.path, SiteSetting.recompress_original_jpg_quality).present?
end