Converting Fonts for the Web Revision as of Saturday, 30 January 2021 at 19:34 UTC
Encode and Decode
Encode
function dataurl() {
local MIMETYPE
MIMETYPE=$(file -b --mime-type "$1")
if [[ $MIMETYPE == text/* ]]; then
MIMETYPE="${MIMETYPE};charset=utf-8";
fi
echo "data:${MIMETYPE};base64,$(openssl base64 -in "$1" | tr -d '\n')";
}
Decode
#!/bin/bash
ENCODED_FILE=$1
sed 's/data:application\/font-woff;base64,//g' "$ENCODED_FILE" | base64 -D > "${ENCODED_FILE%%.*}.woff"
WOFF, WOFF2, TTF, OTF, and SVG
Install FontForge (on Homebrew) and then save this as a script (convert.pe
) and make it executable. Now you can convert whatever you’d like.
Open($1)
Generate($1:r + ".ttf")
Generate($1:r + ".otf")
Generate($1:r + ".svg")
Run with
fontforge -script name_of_script font.woff
Deprecated Stuff
EOT (Deprecated Format)
Install ttf2eot
via Brew and then
ttf2eot Inconsolata.otf > Inconsolata.eot
For a bunch of files,
for f in *.otf; do ttf2eot $f > ${f%".otf"}.eot; done
Utilities
Install this via Homebrew and convert away. It installs this script and a bunch of dependencies.