Comments (7)
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?
from cms.
@maxstrebel You can use the Selectable Assets Condition to only allow SVG!
@i-just Correct me if I'm wrong :)
from cms.
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.
from cms.
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
from cms.
@MangoMarcus, it looks like you might have extraFileKinds
specified in your config, and you’re adding the SVG file type through it.
That’s fine, but since the svg
extension is classed as an “Image” file type by default, if you want to move it to its own file type, you might want to consider removing it from the “Image” file type via, e.g. EVENT_REGISTER_FILE_KINDS.
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 transformSvgs
config setting.
I hope this helps!
I’ll close this now, but feel free to get in touch if you run into any further issues.
from cms.
I too had trouble in the past with transforms when the asset is an svg. Solved it with something like @manud99 's method. Will try to post an example later.
Edit: Just saw the last comment by @i-just , so I won't post anything further here since it's not entirely about the original issue.
from cms.
Thanks to all of you. That are two helpful tips.
from cms.
Related Issues (20)
- [4.x]: Migration throws error relating to UserGroupEvent when removing a user group HOT 5
- [4.x]: Links in release note alerts not rendered HOT 1
- [5.x]: Migration `m230511_215903_content_refactor` fails HOT 3
- Revisions for singles - Remove other sites from the author view (multisite) HOT 6
- [4.x]: error: Undefined array key "label" HOT 1
- Response Headers Ignoring Header Tags [4.x]: HOT 6
- [5.x]: Pagination info on overview page not updating after bulk editing with filter applied HOT 2
- [5.x]: Setting field values in Entry::EVENT_BEFORE_SAVE doesn't work when $firstSave is true
- [5.x]: Custom field conditions in element queries are case-sensitive now
- [5.x]: Incorrect CP console request URLs HOT 1
- [5.x]: Matrix blocks can't be reordered HOT 1
- [5.x]: web-auth/webauthn-lib 4.8.x has security advisory, conflicts with roave/security-advisories
- [5.x]: Entry types that were converted from Matrix block types should have the slug hidden by default HOT 1
- [5.x]: files being deleted from volume upon interaction before completion of image transforms
- [5.x]: Table entries cannot be drag/dropped to re-order on touch devices
- [5.x]: Assets UI Blank Headings Created when Temporary Uploads is Disabled HOT 4
- [5.x]: no option to change element index view on mobile and export button missing HOT 1
- [4.x]: `Element:: EVENT_DEFINE_SIDEBAR_HTML ` not working for `User` elements
- [5.x]: Exporting entries from element index table only exports the first page HOT 1
- [5.x]: Section - Previewlink URL not taking .env parameter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cms.