Skip to content

Instantly share code, notes, and snippets.

@andreif
Last active January 30, 2018 06:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save andreif/1691ee0a22458e4a6589 to your computer and use it in GitHub Desktop.
Save andreif/1691ee0a22458e4a6589 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/icon_16x16@2x.png
convert logo.png -resize 32 python.iconset/icon_32x32.png
convert logo.png -resize 64 python.iconset/icon_32x32@2x.png
convert logo.png -resize 128 python.iconset/icon_128x128.png
convert logo.png -resize 256 python.iconset/icon_128x128@2x.png
convert logo.png -resize 256 python.iconset/icon_256x256.png
convert logo.png -resize 512 python.iconset/icon_256x256@2x.png
convert logo.png -resize 512 python.iconset/icon_512x512.png
convert logo.png -resize 1024 python.iconset/icon_512x512@2x.png
iconutil -c icns python.iconset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment