Class: Scruffy::Rasterizers::RMagickRasterizer

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

Overview

RMagickRasterizer

Author

Brasten Sager

Date

August 14th, 2006

The RMagickRasterizer converts SVG graphs to images using ImageMagick.

Instance Method Summary collapse

Instance Method Details

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scruffy/rasterizers/rmagick_rasterizer.rb', line 10

def rasterize(svg, options={})
  # I know this seems weird, I'm open to suggestions.
  # I didn't want RMagick required unless absolutely necessary.
  require 'RMagick'

  image = Magick::Image::from_blob(svg)[0]

  # Removed for now
  # image.resize!(options[:size][0], options[:size][1], Magick::BoxFilter, 1.25) if options[:actual_size]

  if options[:to]
    image.write(options[:to]) { self.format = options[:as] }
  end

  image.to_blob { self.format = options[:as] }
end