Last active
December 28, 2022 12:51
-
-
Save Thomashighbaugh/39b2a356ed391879ba18ab4be17e85f7 to your computer and use it in GitHub Desktop.
A script I use to convert all my fonts from OTF/TTF to WOFF/WOFF2/EOT
This file contains hidden or 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/bash | |
# Author: Thomas Leon Highbaugh | |
# Description: Assuming you have the dependencies installed, | |
# this will convert your various OTF fonts to TTF than all your TTF fonts to WOFF, | |
# WOFF2 and EOT. This streamlines including fonts on websites, though consult with | |
# the font's license before using them for such! | |
# | |
# Note: for my own purposes, I have included the dependency installation commands that | |
# as they are found on archlinux's repositories and the AUR, adjust this to your own distro | |
# or comment them out otherwise you might have a bad time. | |
# | |
# Dependencies: | |
# npm: | |
# - ttf2woff | |
# - ttf2woff2 | |
# - ttf2eot | |
# pip: | |
# - otf2ttf | |
# distro: | |
# - fontconfig | |
# --------------------------------------------------- # | |
# TODO addin WOFF2 conversions | |
# --------------------------------------------------- # | |
# ------------------- Preliminary ------------------- # | |
# --------------------------------------------------- # | |
# Remove the spaces in font names and curse the bastards who put them there | |
find . -name "* *" | awk '{ print length, $0 }' | sort -nr -s | cut -d" " -f2- | while read f; do base=$(basename "$f"); newbase="${base// /_}"; mv "$(dirname "$f")/$(basename "$f")" "$(dirname "$f")/$newbase"; done | |
# --------------------------------------------------- # | |
# ------------------ Convert Fonts ------------------ # | |
# --------------------------------------------------- # | |
# Convert OTF fonts to TTF | |
for i in **/*.otf; do otf2ttf $i && echo $i; done | |
# --------------------------------------------------- # | |
# Convert the TTF files to EOT for web | |
for i in **/*.ttf; do ttf2eot < $i > $i.eot && echo $i; done; rename 's/\.ttf//' *.eot | |
# --------------------------------------------------- # | |
# Convert the TTF files to WOFF for web | |
for i in **/*.ttf | |
do | |
ttf2woff $i $i.woff | |
echo $i.woff | |
done | |
# --------------------------------------------------- # | |
# Convert TTF to WOFF2 | |
for i in **/*.ttf | |
do | |
cat $i | ttf2woff2 > $i.woff | |
done | |
# --------------------------------------------------- # | |
# ------- Move Fonts To Their Respective Dirs ------- # | |
# --------------------------------------------------- # | |
# Move all the woff to their own directory now that they are renamed | |
for f in **/*.woff | |
do | |
mv -v $f WOFF/ | |
done; | |
# --------------------------------------------------- # | |
# Move all the otf to their own directory now that they are renamed | |
for f in **/*.otf | |
do | |
mv -v $f OTF/ | |
done; | |
# --------------------------------------------------- # | |
# Move all the woff to their own directory now that they are renamed | |
for f in **/*.ttf | |
do | |
mv -v $f TTF/ | |
done; | |
# --------------------------------------------------- # | |
# Move all the EOT files to their directory | |
for f in **/*.eot | |
do | |
mv -v $f EOT/ | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment