Class: Thwomp::AnimationPreview

Inherits:
Object
  • Object
show all
Defined in:
lib/thwomp/animation_preview.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frames) ⇒ AnimationPreview

Returns a new instance of AnimationPreview.



11
12
13
# File 'lib/thwomp/animation_preview.rb', line 11

def initialize(frames)
  @frames = frames
end

Instance Attribute Details

#framesObject (readonly)

TODO: (optional) use Thumbnail class to make png’s from the rendered frames, instead of passing the frames directly to ‘convert’



9
10
11
# File 'lib/thwomp/animation_preview.rb', line 9

def frames
  @frames
end

Instance Method Details

#generate!Object



15
16
17
18
19
# File 'lib/thwomp/animation_preview.rb', line 15

def generate!
  filename = "#{Dir.tmpdir}/animation_#{Time.now.to_i}.gif"
  Command.exec("convert #{frames.join(' ')} #{filename}")
  filename
end

#gif_dataObject

returns the gif binary data of generated animation



22
23
24
# File 'lib/thwomp/animation_preview.rb', line 22

def gif_data
  File.open(generate!, 'rb') { |f| f.read }
end