Class: Scruffy::Rasterizers::BatikRasterizer

Inherits:
Object
  • Object
show all
Defined in:
lib/scruffy/rasterizers/batik_rasterizer.rb

Overview

Scruffy::Rasterizers::BatikRasterizer

Author

Brasten Sager

Date

August 14th, 2006

Purely experimental. Can be used to rasterize SVG graphs with Apache Batik.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BatikRasterizer

Returns new BatikRasterizer.

Options:

command

Command needed to execute Batik. (ie: ‘java -classpath …’)

temp_folder

Folder for storing temporary files being passed between Scruffy and Batik.



15
16
17
18
# File 'lib/scruffy/rasterizers/batik_rasterizer.rb', line 15

def initialize(options={})
  @command = options[:command]
  @temp_folder = options[:temp_folder]
end

Instance Method Details

#rasterize(svg, options = {}) ⇒ Object

Rasterize graph.

Options:

as

Image format to generate (PNG, JPG, et al.)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/scruffy/rasterizers/batik_rasterizer.rb', line 24

def rasterize(svg, options={})
  File.open(@temp_folder + '/temp_svg.svg', 'w') { |file|
    file.write(svg)
  }
  
  `#{@command} -d #{@temp_folder} -m image/#{options[:as].downcase} #{@temp_folder}/temp_svg.svg`
  
  image = ""
  File.open(@temp_folder + '/temp_svg.' + options[:as].downcase, 'r') { |file|
    image = file.read
  }
  
  image
end