ImageDecoder
TheImageDecoder class decodes compressed image data (JPEG, PNG, WebP, GIF, AVIF) into VideoFrame objects that can be processed, edited, or re-encoded.
This implementation follows the W3C WebCodecs ImageDecoder specification.
Quick Example
Decode a JPEG or PNG image into a VideoFrame:Supported Formats
Use
ImageDecoder.isTypeSupported() to check format support at runtime.
Constructor
Parameters
Configuration object for the decoder.
Example
Accessors
Whether all image data has been received and parsed.For images loaded from a
Buffer, this is true immediately after construction.
For images loaded from a ReadableStream, this becomes true when the stream ends.A promise that resolves when
complete becomes true.Use this to wait for the image to be fully loaded before decoding:The MIME type of the image being decoded.
Static Methods
isTypeSupported()
Example: Check format support
Example: Check format support
type(string): The MIME type to check
Promise<boolean> - Resolves to true if the format is supported
Instance Methods
decode()
Example: Basic decode
Example: Basic decode
Example: Animated GIF frame extraction
Example: Animated GIF frame extraction
Example: WebP animation processing
Example: WebP animation processing
Optional decode options.
Promise<ImageDecodeResult> - Resolves to an object containing the decoded frame
reset()
Example: Reset and re-decode
Example: Reset and re-decode
void
close()
Example: Proper cleanup
Example: Proper cleanup
void
Interfaces
ImageDecodeResult
The result of a decode operation.The decoded image as a
VideoFrame. You must call close() on this frame when done to release memory.Whether the image is fully decoded. For animated images, this indicates whether this is the last frame.
ImageDecodeOptions
Options for thedecode() method.
The index of the frame to decode (0-based). Defaults to
0.Whether to only return complete frames. Defaults to
true.ImageDecoderInit
Configuration for creating anImageDecoder.
The compressed image data.
The MIME type of the image.
Color space conversion mode.
Desired output width for scaling.
Desired output height for scaling.
Whether to prefer animated representation.
See Also
VideoFrame
Learn about the VideoFrame class returned by decode()
VideoEncoder
Encode decoded images into video
Thumbnail Generation
Generate thumbnails from images and videos
Video Transcoding
Complete transcoding workflow