ruby-libgd

add_frame

gif.add_frame(image, delay: 50)

Adds a frame to the animated GIF.


Overview

add_frame takes a rendered GD::Image and appends it as a frame in the animated GIF.

Frames are played back in the order they are added.


Parameters

image (GD::Image)

The image to use as a frame.

img = GD::Image.new(200, 200)
gif.add_frame(img)

delay (Integer, optional)

The duration each frame is displayed.

gif.add_frame(img, delay: 10)

Behavior


Notes


Example

gif = GD::Gif.new("animation.gif")

10.times do |i|
  img = GD::Image.new(200, 200)

  img.filled_circle(
    100,
    100,
    20 + i * 5,
    GD::Color.rgb(255, 0, 0)
  )

  gif.add_frame(img, delay: 5)
end

gif.close