From 784e92949972997aba9f09d4cc61414810324ccd Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 19 Jul 2021 15:10:17 -0400 Subject: [PATCH] upload_creator: force ImageMagick to use internal SVG code to determine size This change largely targets dev users, but it could potentially change behaviour in production. Jamie Wilson & I debugged a problem where "should not be larger than the maximum thumbnail size" would fail due to timeouts. On our systems, on ImageMagick 7.1.0-2, with inkscape installed, IM would attempt to rasterise the svg then check the resulting filesize, causing the test to timeout. As of now, we haven't found a way to cause this to behave better, but have a workaround in that forcing IM to use the internal renderer (`MSVG:`) seems to make it perform the same on development workstations as it does in our docker container. --- lib/upload_creator.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb index e5c43dc0240..30b4ff99e6d 100644 --- a/lib/upload_creator.rb +++ b/lib/upload_creator.rb @@ -127,10 +127,14 @@ class UploadCreator if @image_info.type.to_s == 'svg' w, h = [0, 0] + # identify can behave differently depending on how it's compiled and + # what programs (e.g. inkscape) are installed on your system. + # 'MSVG:' forces ImageMagick to use internal routines and behave + # consistently whether it's running from our docker container or not begin w, h = Discourse::Utils - .execute_command("identify", "-ping", "-format", "%w %h", @file.path, timeout: Upload::MAX_IDENTIFY_SECONDS) - .split(' ') + .execute_command("identify", "-ping", "-format", "%w %h", "MSVG:#{@file.path}", timeout: Upload::MAX_IDENTIFY_SECONDS) + .split(' ').map(&:to_i) rescue # use default 0, 0 end