svg2ico converts SVG images into ICO images. It is written in Java, and is available as an Ant task. It is open source, and free for you to use.

The latest version of svg2ico available for download is 2.6. The javadoc is also available online.

The project is hosted on GitHub.

Downloads

Argo is available under the Apache 2 license. It can be downloaded in four forms:

plugins {
    id("com.gitlab.svg2ico") version "2.6"
}
<dependency>
    <groupId>net.sourceforge.svg2ico</groupId>
    <artifactId>svg2ico</artifactId>
    <version>2.6</version>
</dependency>
  • as a jar, to use as an Ant task or from the command line, with source code and shadowed dependencies included,

  • or as the full source code including tests etc. using Git from https://github.com/svg2ico/svg2ico.git.

Previous versions are also available.

Gradle Instructions

Add the plugin to your build

Either Kotlin:

plugins {
    id("com.gitlab.svg2ico") version "2.6"
}

or Groovy:

plugins {
    id 'com.gitlab.svg2ico' version '2.6'
}

Add a task to make an ICO

Kotlin:

tasks.register("ico", com.gitlab.svg2ico.Svg2IcoTask::class) {
    source {
        sourcePath = file("resources/favicon.svg")
    }
    destination = project.layout.buildDirectory.file("icons/favicon.ico")
}

Groovy:

task ico (type : Svg2IcoTask) {
    source {
        sourcePath = file('resources/favicon.svg')
    }
    destination = project.layout.buildDirectory.file('icons/favicon.ico')
}

Add a task to make a PNG

Kotlin:

tasks.register("png", com.gitlab.svg2ico.Svg2PngTask::class) {
    source = file("resources/favicon.svg")
    width = 128
    height = 128
    destination = project.layout.buildDirectory.file("icons/favicon.png")
}

Groovy:

task png (type : Svg2PngTask) {
    source = file('resources/favicon.svg')
    width = 128
    height = 128
    destination = project.layout.buildDirectory.file('icons/favicon.png')
}

Stylesheets

Both tasks accept a userStyleSheet parameter to specify a stylesheet to apply to the SVG, for example:

tasks.register("ico", com.gitlab.svg2ico.Svg2IcoTask::class) {
    source {
        sourcePath = file("resources/favicon.svg")
        userStyleSheet = file("resources/user.css")
    }
    destination = project.layout.buildDirectory.file("icons/favicon.ico")
}

Refinements to ICO output

An ICO file can contain images at multiple resolutions, allowing the client to pick the most appropriate resolution. By default, the svg2ico task will produce an ICO containing 64 x 64, 48 x 48, 32 x 32, 24 x 24, and 16 x 16 pixel resolutions.

The task supports specifying a different set of resolutions if you want to reduce the file size, or if you know the ICO will be rendered at a particular resolution, for example.

It’s also possible to specify different source SVGs for different resolutions, so you can use a detailed source SVG for high resolutions and a simplified one for low resolutions.

The following example makes an ICO with a 64 x 64 image from a detailed SVG, and a 32 x 32 image from a simplified SVG.

tasks.register("ico", com.gitlab.svg2ico.Svg2IcoTask::class) {
    source {
        sourcePath = file("resources/detailed-favicon.svg")
        output { width = 64; height = 64 }
    }
    source {
        sourcePath = file("resources/simplified-favicon.svg")
        output { width = 32; height = 32 }
    }
    destination = project.layout.buildDirectory.file("icons/favicon.ico")
}

Command Line Example

svg2ico can be used from the command line to convert resources/favicon.svg to an ICO like this:

./svg2ico-2.6.jar -src resources/favicon.svg -dest favicon.ico -width 32 -height 32

Three additional optional arguments are supported. -depth specifies the colour depth in bits per pixel, e.g. -depth 8 outputs eight bits per pixel. The -compress flag causes the output to be compressed ICO format. The -userStylesheet allows a user stylesheet file to use during rendering to be provided, for example -userStylesheet ./my-style.css.

Ant Example

svg2ico can be used as an Ant task to convert resources/favicon.svg to an ICO like this:

<target name="Convert SVG to ICO">
    <taskdef name="svg2ico"
        classname="net.sourceforge.svg2ico.Svg2IcoTask"
        classpath="lib/build/svg2ico-2.6.jar"
    />
    <svg2ico src="resources/favicon.svg"
        dest="resources/favicon.ico"
        width="32"
        height="32"
    />
</target>

where lib/build/svg2ico-2.6.jar points to where the svg2ico jar can be found. As with the command line, three optional attributes are supported. depth specifies the colour depth in bits per pixel, e.g. depth="8" outputs eight bits per pixel. compress causes the output to be compressed ICO, e.g. compressed="true". userStylesheet specifies a user stylesheet to use for rendering, e.g. userStylesheet="resources/favicon.css".

Credits

svg2ico uses the excellent Batik and image4j.