Created
August 20, 2021 15:24
-
-
Save gapurov/ece16f3b2de818c0de53628582346f0d to your computer and use it in GitHub Desktop.
OTF to WOFF,WOFF2,TTF convertion cli
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
#!/usr/bin/env bash | |
# usage for multiple files | |
# for file in *.otf; do ./convert-font.sh "$file" .; done | |
set -e | |
SOURCE=$1 | |
DESTINATION=$2 | |
FILENAME=$(basename "${SOURCE%.otf}") | |
# we omit mime check since we use this script only locally and assume it's otf | |
if [[ ${SOURCE: -4} != ".otf" ]]; then | |
echo "usage: convertOtf input.otf /path/to/output/" | |
exit 1 | |
fi | |
# check the destination is a folder | |
if [[ ! -d "$DESTINATION" ]]; then | |
echo "usage: convertOtf input.otf /path/to/output/" | |
exit 1 | |
fi | |
ALLCOMMANDS=( | |
sfnt2woff | |
woff2_compress | |
) | |
# iterate the ALLCOMMANDS list to check for each required command | |
# skip as soon as a command is not found | |
for CMD in "${ALLCOMMANDS[@]}" | |
do | |
: | |
if [[ ! -f $(command -v "$CMD") ]];then | |
echo "Cannot convert ($CMD). The following packages are required: woff-tools woff2" | |
exit 1 | |
fi | |
done | |
echo "[OTF --> WOFF]" | |
sfnt2woff ${SOURCE} | |
echo "[OTF -> WOFF2]" | |
woff2_compress ${SOURCE} | |
echo "[WOFF2 -> TTF]" | |
woff2_decompress ${SOURCE%.otf}.woff2 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment