Last active
September 30, 2019 09:59
-
-
Save johnjcamilleri/72aca7faff569685dbf3de488a7ba3ce to your computer and use it in GitHub Desktop.
Convert FontAwesome's SVG icons to PNG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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