How to convert WOFF to TTF/OTF via command line?
Asked Answered
E

8

52

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?

Eroto answered 26/1, 2012 at 12:11 Comment(1)
Looking at the headline, WOFF (Web Open Font Format) is so inconsistently named. W3C should have just gone for "Web Truetype Font".Coattail
B
68

I wrote a simple tool for that:

https://github.com/hanikesn/woff2otf

Currently only tested with ttf files.

Brierwood answered 29/4, 2012 at 18:8 Comment(5)
Great work man. Shebang does not work on osx, was fixed by feeding it into the interpreter.Griskin
Windows says every OTF it outputs is "not a valid font file"Holstein
not working - @Supuhstar my experience as well (Win7ultimate, py3.4.3)Marinate
Can you explain the philosophy of how it works so I can build one for myself? :)Finegan
@barethon: Since the source code is so short, would you mind including it in your answer, so that it is preserved for the future?Impersonate
F
10

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.

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.


Convert 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

Convert WOFF2 to OTF/TTF 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, you can convert a single WOFF2 to TTF/OTF by running:

woff2_decompress.exe <inputfile>.woff2

To convert all WOFF2 files in the current folder to back to TTF or OTF:

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

You can even convert a TTF/OTF file to WOFF2:

woff2_compress.exe <inputfile>.ttf

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

Freezer answered 17/9, 2019 at 14:48 Comment(3)
From what I see, these tools convert from OTF/TTF to WOFF, not the other way around. My question was looking specifically for tools that convert from WOFF back to OTF/TTF.Eroto
Note on Ubuntu 18.04, you should do woff2_compress instead of woff2_compress.exe. Same goes for other commands.Constabulary
@JonasLekevicius That's what woff2_decompress does, as demonstrated in the last example. Google's WOFF2 CLI package has two executables: woff2_compress for converting from OTF/TTF to WOFF2, and woft2_decompress for converting from WOFF2 to OTF/TTF.Freezer
R
7

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
Reclamation answered 8/5, 2016 at 16:19 Comment(2)
The WOFF code has woff2sfnt and and the WOFF2 code has woff2_decompress. From an ethical standpoint, it’s better to get the font name in Mozilla by highlighting the text, right clicking “inspect element”, going to “font”, seeing the font name, and then using a search engine to find and buy the font in question. If the font is open source, this is definitely the best approach because the WOFF/WOFF2 file on a webpage is probably subsetted or otherwise crippled.Reclamation
The author is asking for how to convert WOFF → TTF/OTF. This post describes TTF → WOFF & WOFF2.Centro
D
7

On a Mac with Homebrew it's simpler than the other mentioned approaches.

.woff2 to .ttf

brew install woff2
woff2_decompress somefont.woff2

This will leave you with somefont.ttf in the same directory.

.woff to .ttf

Converting WOFF (not woff2) is a little trickier, woff2_decompress probably won't handle it. You would first want to convert the .woff file to .woff2, then use the woff2_decompress command to turn that into .ttf file.

There's a brew tap that can be used to install sfnt2woff, which can be used to convert your .woff to .woff2.

brew tap bramstein/webfonttools;
brew install sfnt2woff;
sfnt2woff somefont.woff;
woff2_decompress somefont.woff2
Damson answered 15/9, 2022 at 15:34 Comment(2)
It's worth noting that the solution is similarly simple on Linux: woff2 can likely be found in your distribution's repository. E.g. on Debian-based distros, you can install it using "sudo apt install woff2".Soliz
It's also worth noting that this solution is none other than Google's and Bramstein's posted above :-)Crouton
G
5

Ive been looking for this too but, sorry i couldn't find an offline one but i found this:

http://orionevent.comxa.com/woff2otf.html - no longer available

its really good

EDIT: Found a command line tool

https://superuser.com/questions/192146/converting-from-woffweb-open-font-format

Go answered 3/2, 2012 at 16:6 Comment(1)
Yes, I have been using this. However, I'm looking specifically for a way for this to work offline.Eroto
V
3

I used the python script linked above by barethon to write an online javascript converter of WOFF to OTF

Voltmer answered 21/11, 2014 at 22:3 Comment(6)
Can you explain the philosophy behind it so that I can build one myself?Finegan
Also, is there any way to create ttf files instead of otf? Is pako_inflate.js necessary? That's node, not vanilla, right?Finegan
I can’t explain that. I literally translated Python to Javascript.Voltmer
without generally understanding what was happening? how does the conversion work, is it simply adjusting metadata of the container or?Finegan
Yes, without generally understanding it, at least no trace of such understanding is left. It’s been five years anyway.Voltmer
ok, so it shouldnt be that difficult then? do u know if theres a particular reason why woff2 wont work? is it the same process with woff2 i.e. removing or changing metadata?Finegan
I
2

EverythingFonts has an online tool that appears to work well.

If you wish to do it offline, following Erik Tjernlund's answer on Super User, you can downloaded the source and compile executables of woff2sfnt and sfnt2woff.

The latest version as of this writing was from 2009/09/09. Unfortunately I've discovered that it doesn't appear to work for all WOFF files, sometimes complaining of a bad signature and sometimes simply giving a broken OTF file.

Irretentive answered 19/9, 2013 at 13:0 Comment(0)
G
2

I realise this thread has been inactive for some time now, but with the help of a few stackoverflow users, I was able to use the above mentioned python script [woff2otf.py by @hanikesn] to create a workflow allowing batch conversion of woff files.

If not for the original poster's use, then for others who come across this thread in search of the same thing, check out my thread for details on how to do this:

Modify Python Script to Batch Convert all "WOFF" Files in Directory

Even if you don't need to batch convert, onlinefontconverter.com produces unreliable results, and everythingfonts.com has a 0.4 MB limit on conversions unless you upgrade to a paid account, and both are needlessly time consuming compared to offline solutions.

Good luck!

Grote answered 28/12, 2015 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.