Should svg be included in ActiveStorage variable_content_types

Currently, ActiveStorage.variable_content_types includes the following image formats:

  • image/png
  • image/gif
  • image/jpeg
  • image/tiff
  • image/bmp
  • image/vnd.adobe.photoshop
  • image/vnd.microsoft.icon
  • image/webp
  • image/avif
  • image/heic
  • image/heif

I’ve tried with both image processors (vips and imagemagick), adding SVG image to the above list and processing it works as expected:

# config/application.rb
config.active_storage.variable_content_types << "image/svg+xml"

# show.html.erb
<%= image_tag @model.logo.variant(format: :webp).processed.url %>

I couldn’t find any discussion on this, so, I was wondering if SVG was left out for a reason. If not, if it can be added to the variable image list.

Note. Specifically, I’m coming from Inline SVGs not displayed when loaded from ActiveStorage. By allowing SVG to be variable, developer could render SVG as a variant in one of the web image types with no further configuration or security risk.

That depends on if both vips and imagemagick can handle that, at the minimum version they are required at currently. If another dependency or a higher version is required, I don’t think it’s worth it and it’s better to leave it up to the developer to add it manually.

Possibly related explanation: why svg image is not treated as web image content types in active storage configuration? · Issue #44768 · rails/rails · GitHub