Created
December 31, 2017 17:14
-
-
Save blizzrdof77/284a4e218b2b79c8941532dace309802 to your computer and use it in GitHub Desktop.
Convert font to specified font types using ruby gem 'convert_font'
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
# ----------------------------------------- | |
# Convert font to specified font types using ruby gem 'convert_font' | |
# | |
# @1 = Font to convert (e.g. 'fonts/ComicSansMS.ttf') | |
# @2 = Font types to convert to (e.g 'svg,woff') | |
# ----------------------------------------- | |
function convert-a-font() { | |
if [[ $(command -v convert_font) = "" ]]; then | |
echo "Ruby gem 'convert_font' must be installed." | |
if [[ $(command -v gem) = "" ]]; then | |
return | |
else | |
echo "Would you like to install it now [y/n]?" | |
read YN | |
case $YN in | |
[Yy]* ) gem install convert_font && echo "";; | |
[Nn]* ) return;; | |
* ) echo "That's not yes or no." && convert-a-font && return;; | |
esac | |
fi | |
fi | |
if [ -z "$1" ]; then | |
echo "Input font file/path:" | |
read INPFILE | |
else | |
INPFILE=$1 | |
fi | |
if [ -z "$2" ]; then | |
echo "Font types separated by commas: [press enter for all (ttf,otf,eot,svg,woff,woff2)]" | |
read OUTPTYPES | |
else | |
OUTPTYPES=$2 | |
fi | |
if [[ $OUTPTYPES = "" ]]; then | |
OUTPTYPES="ttf,otf,eot,svg,woff,woff2" | |
fi | |
INPFILE=$(realpath $INPFILE) | |
cd $(dirname $INPFILE) &>/dev/null | |
convert_font convert -i $INPFILE -f $OUTPTYPES | |
cd - &>/dev/null | |
echo "Converted font to formats $OUTPTYPES" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment