Class: Scruffy::Rasterizers::BatikRasterizer
- Inherits:
-
Object
- Object
- Scruffy::Rasterizers::BatikRasterizer
- 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
-
#initialize(options = {}) ⇒ BatikRasterizer
constructor
Returns new BatikRasterizer.
-
#rasterize(svg, options = {}) ⇒ Object
Rasterize graph.
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(={}) @command = [:command] @temp_folder = [: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, ={}) File.open(@temp_folder + '/temp_svg.svg', 'w') { |file| file.write(svg) } `#{@command} -d #{@temp_folder} -m image/#{[:as].downcase} #{@temp_folder}/temp_svg.svg` image = "" File.open(@temp_folder + '/temp_svg.' + [:as].downcase, 'r') { |file| image = file.read } image end |