Method: Pixelart::Vector#to_image

Defined in:
lib/pixelart/vector.rb

#to_imageObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/pixelart/vector.rb', line 99

def to_image
   ## use an empty image (canvas) with transparent background
   ##   as magick input image
   canvas = Image.new( @width, @height )
   canvas.save( MAGICK_INPUT )

   ## note: magick command line might get way too long, thus,
   ##   save commands to a script
   ## note: save magick input first (see above) before save script
   ##        will (auto-)create missing directories in path (if missing)

  File.open( MAGICK_SCRIPT, 'w:utf-8' ) do |f|
    f.write( "#{MAGICK_INPUT} \\\n" )
    @shapes.each do |shape|
      f.write( "#{shape.to_magick} \\\n" )
    end
    f.write( "-write #{MAGICK_OUTPUT}\n" )
  end

  MiniMagick::Tool::Magick.new do |magick|
    magick.script( MAGICK_SCRIPT )
  end

  Image.read( MAGICK_OUTPUT )
end