visualculture.prototype
clone your own copy | download snapshot

Snapshots | iceberg

No images in this repository’s iceberg at this time

Inside this repository

ttf.rb
application/x-ruby

Download raw (701 bytes)

# encoding: UTF-8
# TTF transducer
$:.unshift File.join(File.dirname(__FILE__), "..")
require 'visualculture'

module VC
  module Transducers
    ttf = lambda {|blob, size|
      tmpfnt = File.join( VC.settings("cache-dir"), "#{blob.id[0..10]}.ttf")
      File.open(tmpfnt, 'w') do |f|
        f.write blob.data
      end
      name =  blob.compose_path_2
      w = size.to_i
      h = (w * 0.75).to_i # So thats kind of arbitrary but it gives good results in general
      %x[convert -font #{tmpfnt} -background transparent -gravity center -size #{w}x#{h} label:'Aa' #{name}]
      name
    }    
    @handlers["application/truetype"] = ttf
    @extensions["application/truetype"] = '.png'
  end
end