Skip to content

Instantly share code, notes, and snippets.

@panzi
Last active December 15, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panzi/5324263 to your computer and use it in GitHub Desktop.
Save panzi/5324263 to your computer and use it in GitHub Desktop.
This downloads all variants of a Google Web Font. Please be sure that the font in question uses a license that allows this.
#!/bin/bash
family=`echo "$1"|tr ' ' '+'`
filename=`echo "$1"|sed 's/ //g'`
weight=$2
subset=$3
if [ "$weight" != "" ]; then
family="$family:$weight"
filename="$filename-$weight"
fi
if [ "$subset" != "" ]; then
family="$family&subset=$subset"
fi
function getfont () {
curl -s -A "$1" "http://fonts.googleapis.com/css?family=$family"| \
grep -io '\<http://[-+%:,/\._?&=#a-z0-9]*'|sort -u| \
while read url; do
mime=`curl -s -I "$url"|grep -io '^Content-Type:.*'|sed 's/Content-Type:\s*\([^;]*\)\(;.*\)\?\s*$/\1/I'|tr -d '\r'`
case "$mime" in
font/eot)
ext="eot"
;;
font/woff)
ext="woff"
;;
font/ttf)
ext="ttf"
;;
image/svg+xml)
ext="svg"
;;
*)
ext="bin"
;;
esac
echo "downloading $filename.$ext"
curl -s "$url" -o "$filename.$ext" || exit 1
done
}
getfont "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)"
getfont "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7"
getfont "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1"
@panzi
Copy link
Author

panzi commented Apr 6, 2013

Usage:

./getwebfont.sh font-family [font-weight] [subset]

Example:

$ ./getwebfont.sh "Open Sans" 400
downloading OpenSans-400.eot
downloading OpenSans-400.woff
downloading OpenSans-400.svg
downloading OpenSans-400.ttf

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