Giter Site home page Giter Site logo

Comments (7)

i-just avatar i-just commented on July 21, 2024 1

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.

MoritzLost avatar MoritzLost commented on July 21, 2024 1

@maxstrebel You can use the Selectable Assets Condition to only allow SVG!

A filename condition that limits selectable assets to files ending with a filename of .svg

@i-just Correct me if I'm wrong :)

from cms.

maxstrebel avatar maxstrebel commented on July 21, 2024

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.

MangoMarcus avatar MangoMarcus commented on July 21, 2024

Hi @i-just , thanks for confirming!

I was confused because Image and SVG are different options here, but maybe that's just me

Screenshot 2024-06-19 at 12 00 17

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.

i-just avatar i-just commented on July 21, 2024

@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.

thupsi avatar thupsi commented on July 21, 2024

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.

maxstrebel avatar maxstrebel commented on July 21, 2024

Thanks to all of you. That are two helpful tips.

from cms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.