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.
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.
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.
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.
There are two tools available to convert TTF to WOFF.
sfnt2woff - found here: http://people.mozilla.com/~jkew/woff/ - This is a command line tool that you should be able to call from Ruby
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With