Skip to content

Instantly share code, notes, and snippets.

@goldalworming
Forked from andreif/python-icon-icns.sh
Created May 15, 2016 06:57
Show Gist options
  • Save goldalworming/72e87f3b93ec7f3ec2366c2c14b1c5ab to your computer and use it in GitHub Desktop.
Save goldalworming/72e87f3b93ec7f3ec2366c2c14b1c5ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# 1. Download SVG
if [ ! -f logo.svg ]; then
curl https://www.python.org/static/community_logos/python-logo-inkscape.svg > logo.svg
fi
# -----------------------------------------------------------------------------
# 2. Make PNG
# http://superuser.com/questions/134679/command-line-application-for-converting-svg-to-png-on-mac-os-x
# Does not work with built-in `qlmanage` - no transparency, square
# Install https://inkscape.org/en/download/mac-os/
inkscape=/Applications/Inkscape.app/Contents/Resources/bin/inkscape
$inkscape $(pwd)/logo.svg --export-png $(pwd)/logo.png --export-dpi 300
p="logo.png: PNG image data, 1620 x 479, 8-bit/color RGBA, non-interlaced"
if [ "$(file logo.png)" != "$p" ]; then
echo "PNG file has unexpected parameters"
exit
fi
# It could probably work with ImageMagick if installed with librsvg.
# Tried without it and the result was horrible.
# convert -density 1200 -resize 200x200 source.svg target.png
# -----------------------------------------------------------------------------
# 3. Crop PNG
# Does not work with built-in `sips` - cannot specify reference point;
# rotating and flipping does not help - reference also moves, wtf.
# brew install imagemagick --with-librsvg
convert -crop 376x376+16+21 logo.png logo.png
# -----------------------------------------------------------------------------
# 3. Make ICNS
# http://stackoverflow.com/questions/6337787/how-can-i-set-the-icon-for-a-mac-application-in-xcode
rm -r python.iconset*
mkdir -p python.iconset
convert logo.png -resize 16 python.iconset/icon_16x16.png
convert logo.png -resize 32 python.iconset/[email protected]
convert logo.png -resize 32 python.iconset/icon_32x32.png
convert logo.png -resize 64 python.iconset/[email protected]
convert logo.png -resize 128 python.iconset/icon_128x128.png
convert logo.png -resize 256 python.iconset/[email protected]
convert logo.png -resize 256 python.iconset/icon_256x256.png
convert logo.png -resize 512 python.iconset/[email protected]
convert logo.png -resize 512 python.iconset/icon_512x512.png
convert logo.png -resize 1024 python.iconset/[email protected]
iconutil -c icns python.iconset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment