Forum software attempting to convert SVG to WebP when attaching.

  • Thread starter Thread starter MatskiMonk
  • 5 comments
  • 1,325 views
Messages
18,005
United Kingdom
United Kingdom
Hello,

It's been noticed that sometimes the forum is performing some kind of conversion on SVG files when attached. An SVG will sometimes end up as a WebP VP8x formatted raster image, simply by attaching it.

There doesn't appear to be a specific pattern. It doesn't do it all the time, and sometimes changing a few characters (for example the RGB value of a colour) in the XML of the SVG file will either trigger the problem, or remove it, so it's not directly related to the content of the file (I had wondered if this is a security issue to prevent dodgy XML being executed).

Zipping files is a workaround, but a bit of a pain.
 
This is likely a result of the recent addition of WebP support. All uploaded images are converted to WebP.

Of course, SVG uploads should be treated as files, but I suspect this XenForo functionality is rasterizing them out of convenience. I don't know if that is working as the XenForo developers intended, though the inconsistent results suggests a bug.

Can you provide examples of different SVGs which are and are not converted? This would be useful in filing the bug report.
 
The attached file called WHITE will convert as soon as it's attached. If you hover over the attachment when you add it, you can already see the file size has reduced from ~15kb to 7.6kb which indicates the conversion has happened.

The file BLUE is the same file, but with the final few characters of the file edited as follows, and saved with a different filename:

From:

SVG:
 fill="#fff"/></svg>

To:

SVG:
 fill="#00f"/></svg>

The Zip file WHITEandBLUE contains both original files. If you extract WHITE from that, you'll see it remains SVG.

One interesting thing to note, is that the attached file keeps it's .svg file extension even when converted. If you download the WHITE file attached, rename the file as *.png , it will open as a normal raster image, so it's performing the Vector > Raster conversion as it might be originally intended to.

Credit to @StPeterMartyr for the WHITE file initially.
 

Attachments

Thanks for the detailed bug report and sample files, @MatskiMonk and @StPeterMartyr. I think I see what is going on here.

The image processing library appears to be interpreting WHITE as a single-color image without transparency, which causes XenForo to treat it as a basic image it assumes can be rasterized. The BLUE file is preserved because the detected contrast against the (default) transparent background creates an alpha channel, effectively signaling to the image processor that it's a more complex image which needs to remain an unprocessed vector.

Of course, XenForo shouldn't be touching SVG files at all, but this edge case appears to trigger unwanted image processing to occur. There's not much I can do now, but I will submit a formal bug report to the XenForo developers and hopefully it will get resolved in the next version.

For now, there are a few ways you can work around this.

First, as you know, you can zip the SVG file before attaching it to prevent any image processing.

Second, if you're editing the SVG file, just ensure it has some element of transparency. You can do this by adding a transparent layer, forcing the image processor to detect an alpha channel, like so:

SVG:
<?xml version="1.0" encoding="UTF-8"?>
<svg width="933.47" height="352.66" version="1.1" viewBox="0 0 246.98 93.31" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
  <rect width="100%" height="100%" fill="none"/>
  <path d="M1.91 93.07c-1.85-.25-2.44-1.7-1.4-3.47..." fill="#fff"/>
</svg>

If you are OK with losing a little bit of color accuracy, you can also set the fill color to be almost white, like #FFFFFE. This will be enough to prevent rasterization.

I will post an update once this is resolved in core, but it might be a few weeks or longer depending on the upcoming XenForo release schedule.
 
Last edited:
Zipping files is a workaround, but a bit of a pain.
It takes nothing to zip and unzip a file, and the GTP zip icon is so cool, the zip looking like a checkered flag.
checkered-flag.gif
 
Back