mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user