Created
September 30, 2024 15:39
-
-
Save samuelint/14a2dcdaf30f4146b4c38eb5f48056dd to your computer and use it in GitHub Desktop.
SVG to Icns and ico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function svg_to_icns(){ | |
# Dependencies | |
# $ brew install png2ico | |
# $ brew install svg2png | |
# | |
# Usage example | |
# $ svg2png -V | |
# 0.1.3 | |
# | |
# $ png2ico -V | |
# png2ico 2002-12-08 (c) Matthias S. Benkmann | |
# | |
# $ svg_to_icns notepad.svg | |
# $ file icons/notepad.icns | |
# notepad.icns: Mac OS X icon, 100192 bytes, "ic12" type | |
local RESOLUTIONS=( | |
16,16x16 | |
32,16x16@2x | |
30,Square30x30Logo | |
32,32x32 | |
64,32x32@2x | |
44,Square44x44Logo | |
48,48x48 | |
50,StoreLogo | |
71,Square71x71Logo | |
89,Square89x89Logo | |
107,Square107x107Logo | |
128,128x128 | |
150,Square150x150Logo | |
142,Square142x142Logo | |
248,Square248x248Logo | |
256,128x128@2x | |
256,256x256 | |
284,Square284x284Logo | |
310,Square310x310Logo | |
512,icon | |
512,256x256@2x | |
512,512x512 | |
1024,512x512@2x | |
) | |
for SVG in $@; do | |
BASE=$(basename "$SVG" | sed 's/\.[^\.]*$//') | |
ICONSET="$BASE.iconset" | |
ICONSET_DIR="./icons/$ICONSET" | |
mkdir -p "$ICONSET_DIR" | |
for RES in ${RESOLUTIONS[@]}; do | |
SIZE=$(echo $RES | cut -d, -f1) | |
LABEL=$(echo $RES | cut -d, -f2) | |
svg2png -w $SIZE -h $SIZE "$SVG" "$ICONSET_DIR"/$LABEL.png | |
done | |
iconutil -c icns "$ICONSET_DIR" | |
done | |
png2ico "./icons/icon.ico" "$ICONSET_DIR"/[email protected] "$ICONSET_DIR"/[email protected] "$ICONSET_DIR"/48x48.png "$ICONSET_DIR"/32x32.png "$ICONSET_DIR"/16x16.png | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment