UNPKG

gif-tools

Version:

A robust, zero-dependency TypeScript library for creating GIF files with support for both static and animated GIFs. Built with modern TypeScript features and designed to work in both Node.js and browser environments.

98 lines (97 loc) 2.89 kB
/** * Modern GIF Writer Implementation * * This implementation provides a clean, type-safe API for writing GIF files * with support for both static and animated GIFs. */ import { OutputStream, IndexedImage, ImageOptions, GlobalColorTableOptions, AnimationOptions } from './types.js'; /** * Writes GIF data to a buffer or stream */ export declare class ByteArrayOutputStream implements OutputStream { private data; writeByte(byte: number): void; writeBytes(bytes: Uint8Array | number[]): void; /** * Returns the written data as Uint8Array */ toUint8Array(): Uint8Array; /** * Returns the written data as Buffer (Node.js) or Uint8Array (browser) */ toBuffer(): Uint8Array | unknown; /** * Clears all written data */ clear(): void; /** * Returns the current size in bytes */ get size(): number; } /** * Main GIF Writer class */ export declare class GifWriter { private readonly output; private hasWrittenHeader; private hasWrittenLogicalScreen; private frameCount; constructor(output?: OutputStream); /** * Writes the GIF header (signature and version) */ writeHeader(): this; /** * Writes the logical screen descriptor and optional global color table */ writeLogicalScreen(width: number, height: number, options?: GlobalColorTableOptions): this; /** * Writes animation control information (Netscape extension) */ writeAnimationInfo(options?: AnimationOptions): this; /** * Writes a graphics control extension */ private writeGraphicsControl; /** * Writes image descriptor */ private writeImageDescriptor; /** * Writes image data with LZW compression */ private writeImageData; /** * Writes data in sub-blocks (max 255 bytes each) */ private writeDataSubBlocks; /** * Writes a single image frame */ writeImage(image: IndexedImage, options?: ImageOptions): this; /** * Writes the GIF trailer */ writeTrailer(): this; /** * Convenience method to write a complete static GIF */ writeStaticGif(image: IndexedImage, globalOptions?: GlobalColorTableOptions, imageOptions?: ImageOptions): this; /** * Convenience method to write a complete animated GIF */ writeAnimatedGif(images: IndexedImage[], globalOptions?: GlobalColorTableOptions, animationOptions?: AnimationOptions, imageOptions?: ImageOptions[]): this; /** * Returns the output stream (useful when using default ByteArrayOutputStream) */ getOutput(): OutputStream; /** * Gets the written data as Uint8Array (only works with ByteArrayOutputStream) */ toUint8Array(): Uint8Array; /** * Gets the written data as Buffer (Node.js) or Uint8Array (browser) */ toBuffer(): unknown; }