class GD2::AnimatedGif
See COPYRIGHT for license details.
Public Instance Methods
add(ptr, options = {})
click to toggle source
# File lib/gd2/animated_gif.rb, line 12 def add(ptr, options = {}) size = FFI::MemoryPointer.new(:int) frame_ptr = if frames.empty? ::GD2::GD2FFI.send(:gdImageGifAnimBeginPtr, ptr.image_ptr, size, -1, 0) else previous_frame_ptr = if options[:previous_frame] options[:previous_frame].image_ptr else FFI::Pointer::NULL end ::GD2::GD2FFI.send(:gdImageGifAnimAddPtr, ptr.image_ptr, size, 0, 0, 0, options[:delay].to_i, 1, previous_frame_ptr) end raise LibraryError if frame_ptr.null? frames << Frame.new(frame_ptr, size) end
end()
click to toggle source
# File lib/gd2/animated_gif.rb, line 32 def end size = FFI::MemoryPointer.new(:int) frame_ptr = ::GD2::GD2FFI.send(:gdImageGifAnimEndPtr, size) raise LibraryError if frame_ptr.null? frames << Frame.new(frame_ptr, size) end
export(filename_or_io)
click to toggle source
# File lib/gd2/animated_gif.rb, line 42 def export(filename_or_io) output = case filename_or_io when String File.open(filename_or_io, 'wb') else filename_or_io end frames.each do |frame| output.write(frame.read) end output.flush output.rewind output end
Private Instance Methods
frames()
click to toggle source
# File lib/gd2/animated_gif.rb, line 62 def frames return @frames if defined?(@frames) @frames = [] ObjectSpace.define_finalizer(@frames, frames_finalizer) @frames end
frames_finalizer()
click to toggle source
# File lib/gd2/animated_gif.rb, line 72 def frames_finalizer proc do each do |frame| ::GD2::GD2FFI.send(:gdFree, frame[:frame_ptr]) end end end