Search code examples
javasvgbatik

How to change the foreground color in svg to png conversion?


I'm converting fontawesome 5 svg files to png using batik-rasterizer:

java -jar batik-rasterizer-1.10.jar -scriptSecurityOff "svg/" -d "output/" -m image/png -w 16 -h 16

How do I change the foreground color of the resulting icons?

EDIT:

According to the documentation, it's possible to change the background color:

-bg alpha . red . green . blue : specifies the background fill color as an ARGB quadruple, where each component is an integer in the range 0—255,

But there is no parameter for the foreground.


Solution

  • I found a solutions, in the batik rasterizer documentation I found the cssUser argument:

    -cssUser file|uri : specifies the CSS user stylesheet to use in addition to any other referenced or embedded stylesheets,

    With the following argument a CSS can be added to the conversion:

    -cssUser convert.css
    

    Here the css which makes the icons color red:

    * {
        fill: #ff0000;
    }
    

    Here the complete call:

    java -jar batik-rasterizer-1.10.jar -scriptSecurityOff "svg/" -d "output/" -m image/png -w 16 -h 16 -cssUser convert.css