Class: PdfExtract::PngView

Inherits:
AbstractView show all
Defined in:
lib/view/png_view.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractView

#auto_color, #initialize, #objects, #singular_name

Constructor Details

This class inherits a constructor from PdfExtract::AbstractView

Class Method Details

.write(render, filename) ⇒ Object



25
26
27
# File 'lib/view/png_view.rb', line 25

def self.write render, filename
  render.write filename
end

Instance Method Details

#render(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/view/png_view.rb', line 8

def render options={}
  img = Magick::Image.new(800, 1000) { self.background_color = "white" }

  objects.each_pair do |type, objs|
    color = auto_color
    objs.each do |obj|
      gc = Magick::Draw.new
      gc.fill = "\##{color}"
      gc.rectangle(obj[:x], obj[:y], obj[:x] + obj[:width],
                   obj[:y] + obj[:height])
      gc.draw img
    end
  end
    
  img
end