In my project I need an icon file (.ICO) for the Windows executable. I'd like to generate that file from an SVG, so it contains several images for different sizes. Is there a maven plugin that can do that for me?
I know I can just put an icon file in my repository, but the source file is an SVG image, so I'd like to avoid tha开发者_StackOverflow中文版t.
I don't think there is some Maven plugin for that. And also the problem goes a bit beyond maven itself.
What you can do is:
- Transform SVG to PNG using Apache Batik Rasterizer
- Transform PNG to ICO using ImageMagick and JMagick wrapper
- Create Apache Ant script that will call 1 and 2, and add it to one of the maven lifesycle phases using AntRun plugin.
I came across your question looking for a solution to a very similar problem. None of the answers given really suited me as I didn't want to get tied into running executables, so I wrote a pure Java Ant task (using Batik and image4j under the covers)
I've open sourced it at http://svg2ico.sourceforge.net/ - maybe you could call it from Maven?
You can rasterize an SVG to a PNG on a web page by using Google's canvg to push it into a Canvas, and then using toDataURL()
on the canvas to get base64-encoded PNG data. You'd then need to decode that.
Or, you could use any number of server-side SVG-to-PNG converters.
Not a better answer than @Andrey's, but showing more options for the first step.
The batik-maven-plugin will at least let you generate a PNG from SVG. Not sure how to generate the ICO, though.
精彩评论