Needs work
Project:
Drupal core
Version:
main
Component:
media system
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
9 Jun 2019 at 18:15 UTC
Updated:
21 Apr 2025 at 09:33 UTC
Jump to comment: Most recent, Most recent file





Comments
Comment #2
cilefen commentedComment #3
reinchekI've reproduced the issue and can confirm what you noticed. The problem is that when media_library module try to build the svg preview creates the render array
'#theme' => 'image_style', '#style_name' => 'media_library'.The image style hook will try to build preview with given style's settings. But there isn't a solution in core to apply a style to an SVG file. Attached you can find a simple patch that i've applied to temporarily resolve the issue.
Comment #4
reinchekComment #5
nikolaatIt looks like that the patch works very well. Thank you!
Comment #6
nikolaatComment #7
alexpottThanks for filing this bug report and for fixing it. Bug fixing is very valuable. However in order to commit a bug fix we need an automated to test to prove that we've fixed the bug and ensure that we don't break it again in the future. For more information about writing tests in Drupal 8 see the following links:
Here we can check if the image style supports the URI using the \Drupal\image\Entity\ImageStyle::supportsUri() method rather than hardcoding svg. There's a good question about what we should do if we can't use the thumbnail formatter. I think displaying the full size image as the patch currently does might not be the right way to go. Not sure what is though.
There's a lot of discussion about SVG image style support in #2652138: Image styles do not play nicely with SVGs
Comment #8
reinchek@alexpott you right when you say
I agree with you. Maybe, as they are saying in the linked post, the right ways are at least 2 or 3:
- install and use ImageMagick instead of GD Toolkit which already supports the svg
- embed in core a dedicated image style which converts the vectorial image to raster one.
- extends the GDToolkit class, using external composer svg library, to also works with svg images.
Comment #9
reinchekComment #10
a.boutakaoua commentedI had the some error can you check the related issue
Comment #13
bkosborneNote this also affects the media library. Media entities use an image field type for the thumbnail, so that means it will try and output SVG media thumbnails using image field formatters, which typically run the source image through an image style. And, as we've already found, image styles don't work with SVGs out of the box unless your image processing library says it can handle them. When it cannot handle them, it hides the image output entirely but still allows contrib to override that behavior. This is what Lightning Media and SVG Image module do. They detect if an SVG image is trying to be output through an image style, and if so, allow it.
Comment #14
phenaproximaI'm going to mark this as a feature request for now, because core doesn't really support SVGs properly and Media Library stays within the boundaries of that assumption.
Comment #15
phenaproximaComment #16
carolpettirossi commentedThe patch doesn't seem to work with the Library. When I upload an SVG image it generates the thumbnail, however, when it goes back to the library the image is empty.
I had to use the combination of this patch + https://www.drupal.org/project/media_thumbnails_svg
Comment #17
liam morlandComment #21
luksakThe patch works for me.
Regarding the comment in #16: This only fixes svgs in in create media form in the media library widget. It doesn't fix the display of the thumbnails for existing media in the widget. For that you'll need media_thumbnails_svg as you already figured out.
Comment #23
johnpitcairn commentedNote if you use a dedicated media type for SVGs (ie"logo" in my case), you can set the image formatter to output "original image" for all view modes, and that will display just fine in the media library and widget.
Comment #24
szato commented@Lukas von Blarer
you are right.
Using the patch from #3 solved the issue on Drupal core 10.2.7
Comment #25
prashant.cThis is a major issue while using SVG images, I faced this while working with SVG images in one of the projects which is using Drupal 10.3.2, but this exists in later versions also. SVG images do not at all appear on the following:
Comment #26
prashant.cThe path submitted in #3 resolves the issue only for the Point 1 (Media library) mentioned in #25
Comment #27
bronismateusz commentedIt helped me to install this module: svg_image
Now the thumbnails display correctly in the admin panel.
Comment #28
prashant.cI came across this comment https://www.drupal.org/project/drupal/issues/3028868#comment-13812371, which highlights that the Drupal image module does not support SVGs for a variety of reasons. Given this, it is unclear whether the current issue is still relevant.
Consequently, it appears that utilizing the SVG Image module might be a more suitable alternative, as it offers a widget and formatter for handling SVG fields.