Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TTF (truetype) to WOFF(webfont) conversion using ruby

How do you convert a .ttf file to .woff file (webfont) using ruby?

We want to allow users to upload a ttf file, convert it and embed the woff file.

like image 283
Alagu Avatar asked Jul 13 '12 18:07

Alagu


People also ask

How do I convert ttf to Web font?

To convert you font, you first need to open the Webfont Generator and click on the box marked with an + in order to upload the OTF/TTF font file. Locate the font file on your computer and click Open. The font file is now uploaded to the Webfont Generator.

Which is better ttf or WOFF?

Choose WOFF: If you're using a modern browser, WOFF wraps both TTF and OTF into a single compressed file. Lighter for loading! Choose WOFF 2.0: The newest version developed by Google. The best format to choose because of its smaller file size and better performance for loading on modern browsers.

Does ttf work on all browsers?

TrueType Font (TTF) TTF has long been the most common format for fonts on Mac and Windows operating systems. All major browsers have supported it.


2 Answers

There are two tools available to convert TTF to WOFF.

  1. sfnt2woff - found here: http://people.mozilla.com/~jkew/woff/ - This is a command line tool that you should be able to call from Ruby

  2. sfntly - found here: http://code.google.com/p/sfntly/ - This is a command-line Java suite developed by Google to do a bunch of font tasks, including WOFF generation.

like image 142
Font Squirrel Avatar answered Sep 22 '22 13:09

Font Squirrel


For anyone that might be interested today, there is a small Ruby gem that I released today. It is using a Haskell binary that I tested on Ubuntu 12TLS, Debian 7 Wheezy and Mac OSX 10.7.5

https://github.com/dachi-gh/webify_ruby

You get WebifyRuby module by requiring webify_ruby and a Convert class on it which is used primarily.

require 'webify_ruby'
@convert = WebifyRuby::Convert.new(
  'public/fonts/my_font.ttf',
  dir:'my_dir_fonts/converted',
  css: 'my_dir_css/stylesheets',
  link_to: 'http://example.com/my_dir_fonts'
)

Only first parameter is required. without link_to for example, generated stylesheet's url's would be relative from .css file to webfont files.

p.s. Currently it works good with ttf files but you can still use it with otf

like image 44
dachi Avatar answered Sep 24 '22 13:09

dachi