-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x]: SVGs are considered "Images" #15226
Comments
Hi, thanks for getting in touch! Yes, by default, SVGs are considered images: https://github.com/craftcms/cms/blob/5.x/src/helpers/Assets.php#L582, and they can be transformed. I just tested various ways of applying transforms for an SVG asset, and they all worked as expected. Could you please share a snippet of your template showing how you’re applying the transform? |
I can confirm that I had problems transforming SVG to JPG or PNG in the past and would also love to have the option to differentiate between image and SVG in the asset field. This would make things a lot easier. In almost every project I have the case that I would rather like the users to only upload SVG (icons for example) in order to be able to tint them. |
Hi @i-just , thanks for confirming! I was confused because Image and SVG are different options here, but maybe that's just me In that case I guess the solution in my case will be to do a check for vector image {% if image.extension == 'svg' %}
{# render <img> ... #}
{% else %}
{# Render <picture>, <source> and <image> ... #}
{% endif %} I will leave this open for @maxstrebel 's point about being able to restrict image file type at the asset field level which might be useful, there doesn't seem to be a way to forbid vector images from asset fields at the moment |
@MangoMarcus, it looks like you might have That’s fine, but since the Here’s a related issue that might shed a bit more light on this: #13376. @maxstrebel, you might find that helpful in your case, too. Finally, it’s also worth mentioning that you can opt out of transforming SVGs altogether via I hope this helps! I’ll close this now, but feel free to get in touch if you run into any further issues. |
@maxstrebel You can use the Selectable Assets Condition to only allow SVG! @i-just Correct me if I'm wrong :) |
Thanks to all of you. That are two helpful tips. |
What happened?
Description
This may be a misunderstanding on my part, but are SVGs supposed to be considered "Images"?
Asset fields have a "Restrict allowed file types" option, which includes options for both "Image" and "SVG", which implies to me that SVGs are not considered images.
However if you select "Image" as the only allowed file type then the field still allows you to select and upload SVGs.
Indeed, if you go to the assets section in the control panel and filter the "File Type" to "Image", you still get SVGs.
This then breaks the image in my template because I'm attempting to apply an image transform to an SVG
Thanks!
Steps to reproduce
Craft CMS version
5.2.0
PHP version
8.7.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: