Uploading an svg image to (include in) a post where either the height or width attribute in the main svg element has a numeric size less than “1” (ignoring the associated units) fails with message
Sorry, but we couldn’t determine the size of the image. Maybe your image is corrupted?
It appears that the height and width attributes are checked, and the upload rejected, before the code associated with FIX - use ImageMagick to determine size of SVG images by jbrw · Pull Request #12230 · discourse/discourse · GitHub gets a chance to use the unit information to figure out the actual display size. A search of the forum for
svg “determine the size of the image” “maybe your image is corrupted”
currently returns 9 results. How to include fontawesome icons in posts? looks like it might have the same cause, but that report is old, and supposedly fixed.
Doing some research, this seems to be a problem with the fastimage library being used. I have created an issue there for SVG images with small dimension detected as zero pixels, ignoring units, and am referencing it here. Assuming the fastimage library gets fixed, it will still probably need a change to discourse to get the updated version.
Here is the xml source for the failing sample svg file.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"
width="1.2in" height="0.9in"
viewBox="0 0 1200 900"
>
<line x1="1100" x2="100" y1="100" y2="800" stroke="#000000" stroke-width="50"/>
</svg>
Below are the images that demonstrate minor modifications that make the above image work in the forum. These match the attachments in the referenced github issue.