Circular Favicon from GitHub Avatar

I wrote a script to generate a circular favicon and Apple Touch icon from my GitHub avatar and generalized it.

Make sure ImageMagick is installed. On macOS:

brew install imagemagick

Copy the script into a file named favicon.sh:

set -eu

if ! command -v convert >/dev/null; then
  echo "error: ImageMagick isn't installed." >&2
  exit 1
fi

if [ $# -eq 0 ]; then
  echo "error: No GitHub username provided." >&2
  exit 1
fi

curl -L "https://github.com/$1.png?size=32" -o input.png

convert input.png \
  -gravity Center \
  \( -size 32x32 \
    xc:Black \
    -fill White \
    -draw 'circle 16 16 16 1' \
    -alpha Copy \
  \) -compose CopyOpacity -composite \
  -trim favicon.ico

curl -L "https://github.com/$1.png?size=180" -o apple-touch-icon.png

Make it executable:

chmod +x favicon.sh

Run it with your GitHub username:

./favicon.sh username

These files will be created:

favicon.ico
apple-touch-icon.png