I have been struggling with the same problem. I have an SVG with the image of my icon and I need to create an icon.ico
file from it. Let me describe the solutions I found:
Step 1: Determine what resolutions to include inside the icon.ico
file.
There are no clear guidelines about that. Even Microsoft ships its software with inconsistent icon resolutions. There is a question about that.
Therefore, I think the best we can do about it is to use IconsExtract from Nirsoft. With such tool, you can check the resolutions included in icons of popular modern Windows programs.
Step 2: Create .png files for every resolution you want to include inside your icon.ico
file.
Many answers suggest to use Inkscape, but you can do everything with ImageMagick in the following way (just in case, I checked that the resulted images are the same as if you used inkscape):
magick.exe convert -size 16x16 -background transparent -depth 8 MyIconImage.svg 16.png
...
magick.exe convert -size 256x256 -background transparent -depth 8 MyIconImage.svg 256.png
However, if you still want to use Inkscape, here's the command:
inkscape.exe MyIconImage.svg -w 16 -h 16 -o 16.png
Some answers also suggest using ImageMagick's icon:auto-resize
command line argument to avoid creating separate PNG files for every resolution. I don't recommend using it because to get the best quality it is better to avoid resizing as it is less accurate than rendering SVG file into each resolution separately.
Step 3: Assemble your icon.ico file.
magick.exe convert 16.png 20.png 24.png 32.png 40.png 48.png 64.png 256.png -compress jpeg icon.ico
-compress jpeg
is used as a workaround for a specific issue in ImageMagick, as described in the following comment.
You can see details about created icon.ico
file using the following command:
magick.exe identify icon.ico
Powershell script "CreateIcoFromSvg.ps1"
Let me provide a powershell script which automates above-mentioned steps:
# You can download ImageMagick from: https://imagemagick.org/script/download.php
$imageMagick = "$PSScriptRoot/ImageMagick-7.1.0-portable-Q16-x64/magick.exe"
$svgIcon = "MySvgIcon.svg"
$iconResolutions = 16,20,24,32,40,48,64,256
# Create 16.png, ..., 256.png image files
$pngImages = @()
Foreach($r in $iconResolutions) {
& $imageMagick convert -size "${r}x${r}" -background transparent -depth 8 $svgIcon "${r}.png"
$pngImages += "${r}.png"
}
# Combine all PNG image files into an icon.ico file
& $imageMagick convert $pngImages -compress jpeg "icon.ico"
# Remove PNG files
Foreach($image in $pngImages) {
Remove-Item $image
}