4

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

Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
Roel Spilker
  • 32,258
  • 10
  • 68
  • 58

4 Answers4

4

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:

  1. Transform SVG to PNG using Apache Batik Rasterizer
  2. Transform PNG to ICO using ImageMagick and JMagick wrapper
  3. Create Apache Ant script that will call 1 and 2, and add it to one of the maven lifesycle phases using AntRun plugin.
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
  • In the ImageMagick documentation, I can't find the option to create .ico files. And I want to have multiple images in one .ico file. Can you point me to that documentation? – Roel Spilker Mar 08 '11 at 15:21
  • 1
    Try using adjoin option: http://www.imagemagick.org/script/command-line-options.php#adjoin – Andrey Adamovich Mar 08 '11 at 15:38
  • Thanks for the link. I'm sorry to say that the JMagick documentation is too sparse to work with. The Javadoc is not helpful at all, and the examples are incomplete. The same goes for the wiki. – Roel Spilker Mar 08 '11 at 15:56
  • I didn't accept it as The Correct Answer yet, since based on your description I still have to work out a lot of details myself, and didn't have the opportunity to do so. Furthermore, I still hope for a better answer :-) – Roel Spilker Mar 08 '11 at 16:00
  • Imagemagick is your best bet, it can convert nearly everything, for documentation look for the generic C examples, the java api is nearly identical – mglauche Mar 08 '11 at 18:12
  • From a different source I got the suggestion to have a look at image4j.sourceforge.net. That looks promising. – Roel Spilker Mar 11 '11 at 10:27
2

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?

Mark Slater
  • 831
  • 7
  • 18
1

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.

Phrogz
  • 296,393
  • 112
  • 651
  • 745
1

The batik-maven-plugin will at least let you generate a PNG from SVG. Not sure how to generate the ICO, though.

mes5k
  • 855
  • 10
  • 15
  • Not possible within `batik-maven-plugin` - yet, suggested feature at https://github.com/trajano/batik-maven-plugin/issues/2 – Kalle Richter Dec 23 '16 at 21:54