Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert TTF files to OTF format?

I need to use @font-face feature and my fonts are in TrueType (TTF) format, so how to convert TTF to OpenType (OTF) format.

like image 289
useCase Avatar asked Apr 19 '11 05:04

useCase


2 Answers

If you are on Linux, you can use FontForge, which can be scripted from Python.

#!/usr/bin/python
import fontforge
font = fontforge.open("STIXGeneral.otf")
font.generate("STIXGeneral.ttf")

Here is a longer python script that does this for a whole directory at a time:

http://fonts.fileformat.info/bin/otf2ttf.py

like image 117
fileformat Avatar answered Oct 15 '22 04:10

fileformat


It was painfully hard to find how to do it correctly. Here is how I got it to work on OS X

$ brew install fontforge
$ fontforge  -c 'Open("my.ttf"); Generate("my.otf")'

I was desperately looking for pip install fontforge which does not exist and I haven't got it to work with python - I guess you need to compile it with --enable-pyextension or something.

like image 11
Andrei Avatar answered Oct 15 '22 04:10

Andrei