Skip to content

Instantly share code, notes, and snippets.

@johnjcamilleri
Last active September 30, 2019 09:59
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 johnjcamilleri/72aca7faff569685dbf3de488a7ba3ce to your computer and use it in GitHub Desktop.
Save johnjcamilleri/72aca7faff569685dbf3de488a7ba3ce to your computer and use it in GitHub Desktop.
Convert FontAwesome's SVG icons to PNG
#!/bin/sh
# Convert all FontAwesome SVGs to PNGs
#
# Instructions:
# 1. Download FontAwesome's desktop package & extract
# 2. Save this script to the root folder & make it executable
# 3. (Optional) Choose conversion method below
# 4. Run! (takes a few minutes to get through the whole collection)
# Dimensions/size are fixed square and icon is padded/centered
# Requires svgexport (https://github.com/shakiba/svgexport, npm install --global svgexport)
# Slow (~1000ms per icon)
convert_fixed() {
svgexport "${1}" "${2}" 512:512 pad
}
# Dimensions/size are not fixed, based on icon itself
# Requires rsvg-convert (https://manpages.ubuntu.com/manpages/trusty/man1/rsvg-convert.1.html, brew install librsvg)
# Fast (~50ms per icon)
convert_natural() {
rsvg-convert "${1}" --output "${2}" --keep-aspect-ratio
echo "${1}"
}
for style in brands duotone light regular solid ; do
mkdir -p "pngs/${style}"
for icon in "svgs/${style}/"*.svg ; do
filename=$(basename -- "${icon}")
name="${filename%.*}"
# convert_fixed "${icon}" "pngs/${style}/${name}.png"
convert_natural "${icon}" "pngs/${style}/${name}.png"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment