resvg icon indicating copy to clipboard operation
resvg copied to clipboard

Allow setting the default `currentColor`

Open condemil opened this issue 1 year ago • 7 comments

Most web icons, including tailwindlabs/heroicons allows to set icon color with css font color on the page/block. This is done with stroke="currentColor" on the svg icon. For now resvg allows to set background color with --background COLOR argument, it would be really nice to have an option to do the same for "foreground" color. This way it would be possible to render icons for dark backgrounds.

condemil avatar May 30 '24 09:05 condemil

What do you mean by "foreground" color? currentColor is background color.

RazrFalcon avatar May 30 '24 11:05 RazrFalcon

It is possible to set icon color on web, here is an example:

<div style="color: red">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor">
        <circle cx="12" cy="12" r="10" />
    </svg>
</div>

But resvg --background white test.svg test.png will render black circle on white background, as there is no possibility now to set the icon color similar way as it is done on web.

condemil avatar May 30 '24 17:05 condemil

I understand your point now and yes it's not possible right now. We probably have to implement #277 first and then you can set color on the root element via CSS.

Unlike Web/HTML, in static SVG currentColor is resolved only inside the file itself. And while we can add an ability to set the default currentColor, it would still be rather limited compared to CSS injection.

RazrFalcon avatar May 31 '24 08:05 RazrFalcon

This is possible now, so I think we can close this issue.

LaurenzV avatar Oct 14 '24 07:10 LaurenzV

You mean via CSS injection?

RazrFalcon avatar Oct 14 '24 07:10 RazrFalcon

Yep.

LaurenzV avatar Oct 14 '24 07:10 LaurenzV

I don't think that's a proper solution. More like a hack. And no one will figure it out unless we document it somewhere...

RazrFalcon avatar Oct 14 '24 07:10 RazrFalcon