Skip to content

Instantly share code, notes, and snippets.

@adriansr
Created February 19, 2018 15:21
  • Star 25 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Convert SVG file to macOS icon (icns) format
#!/bin/sh -x
set -e
SIZES="
16,16x16
32,16x16@2x
32,32x32
64,32x32@2x
128,128x128
256,128x128@2x
256,256x256
512,256x256@2x
512,512x512
1024,512x512@2x
"
for SVG in "$@"; do
BASE=$(basename "$SVG" | sed 's/\.[^\.]*$//')
ICONSET="$BASE.iconset"
mkdir -p "$ICONSET"
for PARAMS in $SIZES; do
SIZE=$(echo $PARAMS | cut -d, -f1)
LABEL=$(echo $PARAMS | cut -d, -f2)
svg2png -w $SIZE -h $SIZE -i "$SVG" -o "$ICONSET"/icon_$LABEL.png
done
iconutil -c icns "$ICONSET"
rm -rf "$ICONSET"
done
@seanr
Copy link

seanr commented May 24, 2021

I think I did brew install svg2png or similar. It's been a while but Google should find current answers.

@0x1D-1983
Copy link

Thank you for this! It works as expected and generates icns files with transparent background. 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment