gif
stableEncode animated GIFs from RGBA frame data using a GifEncoder handle that accumulates frames and serializes them to bytes.
use plugin gif::{GifEncoder, add_frame, finish, …} Functions (8)
- GifEncoder Creates a new GIF encoder handle with the given pixel dimensions.
- add_frame Appends one frame to the encoder.
- finish Encodes all accumulated frames into a valid GIF binary using per-frame palette quantization (up to 256 colors).
- frame_count Returns the number of frames currently queued in the encoder.
- set_loop_count Sets how many times the GIF loops.
- dimensions Returns a table with width and height keys reflecting the encoder's pixel dimensions.
- clear_frames Removes all queued frames, allowing the encoder to be reused for a new animation without creating a new handle.
- set_frame_delay Updates the delay of an already-queued frame at zero-based index.
Creates a new GIF encoder handle with the given pixel dimensions.
Creates a new GIF encoder handle with the given pixel dimensions. Frames added via add_frame are queued in memory until finish is called.
use plugin gif::{GifEncoder}
let enc = GifEncoder(320, 240)
let d = enc.dimensions()
print("encoder ready: {d["width"]}x{d["height"]}")
Appends one frame to the encoder.
Appends one frame to the encoder. rgba_bytes must be a byte sequence of exactly width * height * 4 bytes in RGBA order. delay_ms is the display duration in milliseconds (converted internally to centiseconds).
use plugin gif::{GifEncoder}
let enc = GifEncoder(2, 2)
let frame = [255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255]
enc.add_frame(frame, 500)
print("frames: {enc.frame_count()}")
Encodes all accumulated frames into a valid GIF binary using per-frame palette quantization (up to 256 colors).
Encodes all accumulated frames into a valid GIF binary using per-frame palette quantization (up to 256 colors). Returns the raw GIF bytes ready to write to a file or send over HTTP.
use plugin gif::{GifEncoder}
let enc = GifEncoder(4, 4)
enc.set_loop_count(0)
let gif_bytes = enc.finish()
print("GIF size: {gif_bytes.len()} bytes")
Returns the number of frames currently queued in the encoder.
Returns the number of frames currently queued in the encoder.
use plugin gif::{GifEncoder}
let enc = GifEncoder(10, 10)
print(enc.frame_count())
Sets how many times the GIF loops.
Sets how many times the GIF loops. Pass 0 for infinite looping, or a positive integer for a fixed repeat count.
use plugin gif::{GifEncoder}
let enc = GifEncoder(100, 100)
enc.set_loop_count(3)
Returns a table with width and height keys reflecting the encoder's pixel dimensions.
Returns a table with width and height keys reflecting the encoder's pixel dimensions.
use plugin gif::{GifEncoder}
let enc = GifEncoder(640, 480)
let d = enc.dimensions()
print("{d["width"]}x{d["height"]}")
Removes all queued frames, allowing the encoder to be reused for a new animation without creating a new handle.
Removes all queued frames, allowing the encoder to be reused for a new animation without creating a new handle.
use plugin gif::{GifEncoder}
let enc = GifEncoder(100, 100)
enc.clear_frames()
print("frames after clear: {enc.frame_count()}")
Updates the delay of an already-queued frame at zero-based index.
Updates the delay of an already-queued frame at zero-based index. Useful for adjusting timing after frames are added without re-adding them.
use plugin gif::{GifEncoder}
let enc = GifEncoder(100, 100)
enc.set_frame_delay(0, 1000)