Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert WOFF to TTF/OTF via command line?

I know about services like Online Font Converter, but I am interested in offline solution, preferably over command line. Does anyone know a tool or workflow how to convert WOFF to OTF/TTF offline?

like image 846
Jonas Lekevicius Avatar asked Jan 26 '12 12:01

Jonas Lekevicius


People also ask

Can OTF be converted to WOFF?

CloudConvert converts your font files online. Amongst many others, we support TTF, OTF and WOFF. No need to download any software.

What is the difference between OTF TTF and WOFF?

Web Open Font Format (WOFF)WOFF is basically OTF or TTF with metadata and compression supported by all major browsers. It was created to live on the web. It is the result of collaboration by the Mozilla Foundation, Microsoft, and Opera Software. Because fonts are compressed, they load faster.

Can you Install WOFF fonts in Windows 10?

Microsoft Windows 7–10Close any open applications that will use fonts. Unzip the folder containing the fonts. Right click on the font file and select Install.


3 Answers

I wrote a simple tool for that:

https://github.com/hanikesn/woff2otf

Currently only tested with ttf files.

like image 154
barethon Avatar answered Sep 19 '22 00:09

barethon


Here is the reference code for making WOFF files: http://people.mozilla.org/~jkew/woff/ I have a mirror: https://github.com/samboy/WOFF

To compile and install, make sure you have the zlib development libraries installed (e.g. in CentOS6 yum -y install zlib-devel as root), then

git clone https://github.com/samboy/WOFF cd WOFF make 

Then, as root:

cp sfnt2woff /usr/local/bin 

Once this is done, to make a webfont, enter the directory with the .ttf file, then run sfnt2woff

sfnt2woff Chortle2014f.ttf 

This creates a Chortle2014f.woff webfont file. Replace “Chortle2014f.ttf” with the name of the actual webfont to convert.

The first link I provide has Windows and MacOS binaries for people who do not wish to install a compiler.

Here is the reference code for making WOFF2 files: https://github.com/google/woff2 Note that this code will not install in CentOS6, but compiles and installs just fine in CentOS7:

git clone --recursive https://github.com/google/woff2.git cd woff2 make clean all 

woff2 font generation is similar:

woff2_compress Chortle2014f.ttf 
like image 25
samiam Avatar answered Sep 18 '22 00:09

samiam


I didn't like the fact that the current best answer is a Python script, and there also appear to be cases of people saying it doesn't work. In addition, none of the current answers seem to make mention of compiling WOFF converters with the zopfli compression algorithm, which is superior to the standard zlib algorithm that other tools use. For these reasons I decided to go the "proper" (i.e. non-script) route and add my own answer in the process.

Note: the compilation process for both of the below utilities is very easy, and made even easier by simply copying and running the snippets of code I've provided below, but they do still require a working compiler. If you haven't compiled software from source before, you may need to setup a compiler environment first. If you're using Cygwin, you can follow the first part of my answer here to set up the MinGW-w64 cross-compiler.

WOFF CLI converter (with ZOPFLI compression)

First, compile and install sfnt2woff1 by pasting all of the following into a terminal and pressing Enter:

git clone https://github.com/bramstein/sfnt2woff-zopfli.git woff &&
cd woff &&
make &&
chmod 755 woff2sfnt-zopfli sfnt2woff-zopfli &&
mv woff2sfnt-zopfli sfnt2woff-zopfli /usr/local/bin &&
rm -rf ../woff

Once the tool has been compiled and installed, convert a TTF or OTF file to WOFF by running:

sfnt2woff-zopfli <inputfile>.ttf

You can also use the -n option to increase the number of iterations the program is run in, increasing compression at the cost of conversion time (the default number of iterations is 15).

To convert all files in the current directory to WOFF:

for i in *; \
do sfnt2woff-zopfli.exe "$i"; \
done

WOFF2 CLI converter (with Brotli compression)

First, compile and install Google's woff2 tools by pasting all of the following into a terminal and pressing Enter:

git clone --recursive https://github.com/google/woff2.git &&
cd woff2 &&
make clean all &&
mv woff2_compress woff2_decompress woff2_info /usr/local/bin &&
rm -rf ../woff2

Once the tool has been compiled and installed, convert a single TTF or OTF file to WOFF2 by running:

woff2_compress.exe <inputfile>.ttf

To convert all files in the current directory to WOFF2:

for i in *; \
do woff2_compress.exe "$i"; \
done

You can even convert a WOFF2 file back to TTF or OTF:

woff2_decompress.exe <inputfile>.woff2

1 Note that SFNT here refers to the SFNT table format that both TTF and OTF font formats are built around.

like image 29
Hashim Aziz Avatar answered Sep 22 '22 00:09

Hashim Aziz