Skip to main content

Video API · experimental builder

Turn a sequence of frames into a shareable GIF.

GIFBuilder collects browser images or media frames and produces a base64-encoded GIF. It is useful for small capture and preview workflows, but remains experimental and browser-only.

The capture path

Collect frames first. Encode once at the edge.

GIFBuilder accepts decoded images, URLs, video, and webcam input depending on the selected source. The surrounding application still owns permission, timing, and lifecycle decisions.

Sources

Images, image URLs, video, or webcam frames

Output

Base64-encoded GIF image data

Runtime

Browser APIs only

Status

Experimental; pin versions for production experiments

Detailed guide

GIFBuilder reference

The sections below document construction, frame input, text overlays, webcam capture, methods, and experimental limitations.

From-v2.2

This GIFBuilder is experimental and may change significantly in minor releases and ev en patch releases. Pin down your loaders.gl version if you wish to use it.

The GIFBuilder class creates a base64 encoded GIF image from either:

  • a series of images
  • a series of image URLs
  • a video URL
  • or by capturing the webcam.

The GIFBuilder only works in the browser, and many features are experimental.

Usage​

Build a GIF from images

import {load} from '@loaders.gl/core';
import {ImageLoader} from '@loaders.gl/images/image';
import {GIFBuilder} from '@loaders.gl/images/image';

const gifBuilder = new GIFBuilder({source: 'images', width: 400, height: 400});
gifBuilder.add(await load('http://i.imgur.com/2OO33vX.jpg', ImageLoader));
gifBuilder.add(await load('http://i.imgur.com/qOwVaSN.png', ImageLoader));
gifBuilder.add(await load('http://i.imgur.com/Vo5mFZJ.gif', ImageLoader));
gifBuilder.build();

Build a GIF from image URLs (Experimental)

import {GIFBuilder} from '@loaders.gl/images/image';

const gifBuilder = new GIFBuilder({source: 'images', width: 400, height: 400});
gifBuilder.add('http://i.imgur.com/2OO33vX.jpg');
gifBuilder.add('http://i.imgur.com/qOwVaSN.png');
gifBuilder.add('http://i.imgur.com/Vo5mFZJ.gif');
gifBuilder.build();

Build a GIF from image URLs, with frame-specific Text (Experimental)

import {GIFBuilder} from '@loaders.gl/images/image';

const gifBuilder = new GIFBuilder({source: 'images', width: 400, height: 400});
gifBuilder.add({src: 'http://i.imgur.com/2OO33vX.jpg', text: 'First image text'});
gifBuilder.add({src: 'http://i.imgur.com/qOwVaSN.png', text: 'Second image text'});
gifBuilder.add({src: 'http://i.imgur.com/Vo5mFZJ.gif', text: 'This image text'});
gifBuilder.build();

Build a GIF from the webcam (Experimental)

import {GIFBuilder} from '@loaders.gl/images/image';
const gifBuilder = new GIFBuilder({source: webcam, width: 400, height: 400});
gifBuilder.build();

Methods​

constructor(options: object)​

Creates a new GIFBuilder instance.

options See the Options section below.

add(file: ImageBitmap | Image | string | object)​

  • images -- ImageBitmap and Image objects can be added.

Experimentally, the following types can currently be added (may be removed in upcoming release)

Also note that a mix of types is not supported. All added elements must be of the same type (images, image URLs, video URLs).

build(): string​

The build method will actually build the GIF. It returns a base 64 encoded GIF.

Note: After calling build() this builder instance is not intended to be used further. Create new GIFBuilder instances to build additional GIFs.

Options​

OptionDefaultDescription
source'images'Input kind: 'images', 'video', or 'webcam'.
width200Output width in pixels.
height200Output height in pixels.
crossOrigin'Anonymous'CORS mode for requested images and video.
sampleInterval10Palette sampling interval; smaller values increase work.
numWorkers2Frame-processing workers.
interval0.1Seconds between captured frames.
offsetnullVideo capture start offset in seconds.
numFrames10Number of frames to capture.
frameDuration1Frame duration in tenths of a second.

Smaller sampleInterval values improve palette sampling at the cost of more work.

Experimental options​

These settings are forwarded to the bundled gifshot implementation. They are experimental and may depend on browser image, canvas, and video support.

OptionDefaultDescription
filter''CSS filter applied to frames.
waterMarknullWatermark image.
waterMarkHeightnullWatermark height.
waterMarkWidthnullWatermark width.
waterMarkXCoordinate1Horizontal watermark position.
waterMarkYCoordinate1Vertical watermark position.
text''Text displayed over the GIF.
showFrameTexttrueShow per-frame text when supplied.
fontWeight'normal'Text weight.
fontSize'16px'Text size.
minFontSize'10px'Minimum fitted text size.
resizeFontfalseResize text to fit the GIF.
fontFamily'sans-serif'Text font family.
fontColor'#ffffff'Text color.
textAlign'center'Horizontal text alignment.
textBaseline'bottom'Vertical text baseline.
textXCoordinatenullOverride horizontal text position.
textYCoordinatenullOverride vertical text position.

Remarks​

  • Make sure these image resources are CORS enabled to prevent any cross-origin JavaScript errors
  • You may also pass a NodeList of existing image elements on the page

Attribution​

GIFBuilder is based on Yahoo's awesome gifshot module, and is MIT licensed.