Requirements:
- convert command line tool from ImageMagick (for converting .pngs to .ico)
- Inkscape (for converting .svg to .pngs)
- PowerShell
param(
[Parameter(Mandatory=$true,Position=0)]
[Alias("s")]
$SvgFilename,
[Parameter(Mandatory=$false,Position=1)]
$IcoFilename = ""
)
if (-not [System.IO.Directory]::Exists("tmp")) {
New-Item -Type Directory -Path tmp
}
$sizes = (16, 20, 24, 32, 40, 48, 64, 128, 256)
$filename = [System.IO.Path]::GetFileNameWithoutExtension($SvgFilename)
for ($i = 0; $i -lt $sizes.length; $i++) {
$size = $sizes[$i];
Write-Host $sizes[$i]
Write-Host $filename
inkscape -z -e tmp/${filename}_${size}.png -w $size -h $size -d 300 $SvgFilename
}
if ($IcoFilename.length -eq 0) {
$IcoFilename = $SvgFilename.Replace(".svg", ".ico")
}
if (-not $IcoFilename.EndsWith(".ico")) {
$IcoFilename = "${IcoFilename}/${filename}.ico"
}
Write-Host "Writing $IcoFilename"
convert tmp/${filename}_16.png tmp/${filename}_20.png tmp/${filename}_24.png tmp/${filename}_32.png tmp/${filename}_40.png tmp/${filename}_48.png tmp/${filename}_64.png tmp/${filename}_128.png tmp/${filename}_256.png ${IcoFilename}
Remove-Item -Path tmp -Recurse
Write-Host "Successfully wrote $IcoFilename"
Code language: PHP (php)
Usage:
svg2ico.ps1 device-harddisk-usb.svg device-harddisk-usb.ico
Code language: CSS (css)