The following example Ruby program outputs a simple animation as a series of PNG pictures:
require 'RMagick'
require 'fileutils'
FileUtils::mkdir_p 'images'
# prepare font
smallText = Magick::Draw.new
smallText.font = 'VeraMono'
smallText.pointsize = 40
smallText.gravity = Magick::CenterGravity
original = Magick::Image.new(300, 200) do self.background_color = "black" end
(0...25).each do |frame|
puts "processing frame \##{frame}"
# blur and darken last frame
copy = original.gaussian_blur(10,8).level(0,0.7)
# draw fresh text
smallText.annotate(copy, 0, 0, 0, 0, "frame \#%02d" % frame) do
self.fill = 'white'
end
# Save PNG:
# * Very important! *
# MPlayer only understands PNG images with 8 bits per channel, so the PNG's
# must be encoded with depth=8.
copy.write('images/image%03d.png' % frame) do self.depth = 8 end
original = copy
end
When the program has run, create an AVI file:
mencoder mf://images/*.png -mf w=300:h=200:fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4 -o anim.avi