Svg images with dimension less than 1 fail to upload

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" "">
  xmlns="" xmlns: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"/>

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.

image2 image3 image4

Thanks for the detailed description of the issue.

I’ve managed to recreate the problem on my end, and I think this pull request should address the issue you describe

Edit: Strange… the tests pass for me locally, but are failing after I push them. I will dig in to that tomorrow.


This was merged in last week.

@µMerlin Can you update things on your end and confirm things are OK now?

1 Like

This topic was automatically closed after 4 days. New replies are no longer allowed.