Skip to main content

<Gif>

Part of the @remotion/gif package

Displays a GIF that synchronizes with Remotions useCurrentFrame().

Props

src

required

The source of the GIF. Can be an URL or a local image - see Importing assets.

note

Remote GIFs need to support CORS.

More info
  • Remotion's origin is usually http://localhost:3000, but it may be different if rendering on Lambda or the port is busy.
  • You can disable CORS during renders.

width

The display width.

height

The display height.

fit

Must be one of these values:

  • 'fill': The GIF will completely fill the container, and will be stretched if necessary. (default)
  • 'contain': The GIF is scaled to fit the box, while aspect ratio is maintained.
  • 'cover': The GIF completely fills the container and maintains it's aspect ratio. It will be cropped if necessary.

onLoad

Callback that gets called once the GIF has loaded and finished processing. As its only argument, the callback gives the following object:

  • width: Width of the GIF file in pixels.
  • height: Height of the GIF file in pixels.
  • delays: Array of timestamps of type number containing position of each frame.
  • frames: Array of frames of type ImageData

style

Allows to pass in custom CSS styles. You may not pass width and height, instead use the props width and height to set the size of the GIF.

loopBehaviorv3.3.4

The looping behavior of the GIF. Can be one of these values:

  • 'loop': The GIF will loop infinitely. (default)
  • 'pause-after-finish': The GIF will play once and then show the last frame.
  • 'unmount-after-finish': The GIF will play once and then unmount. Note that if you attach a ref, it will become null after the GIF has finished playing.

refv3.3.88

You can add a React ref to <Gif>. If you use TypeScript, you need to type it with HTMLCanvasElement.

playbackRatev4.0.44

The playbackRate prop controls the playback speed of the GIF animation within your Remotion video. It enables you to adjust how fast or slow the GIF animation plays, allowing for precise synchronization with your video content.

Default: 1 (Normal speed) Values:

  • 1: Plays the GIF at normal speed.
  • < 1: Slows down the GIF speed (e.g., 0.5 plays it at half speed).
  • > 1: Speeds up the GIF speed (e.g., 2.0 plays it at double speed).

Example

tsx
import { Gif } from "@remotion/gif";
 
export const MyComponent: React.FC = () => {
const { width, height } = useVideoConfig();
const ref = useRef<HTMLCanvasElement>(null);
 
return (
<Gif
ref={ref}
src="https://media.giphy.com/media/3o72F7YT6s0EMFI0Za/giphy.gif"
width={width}
height={height}
fit="fill"
playbackRate={2}
/>
);
};
tsx
import { Gif } from "@remotion/gif";
 
export const MyComponent: React.FC = () => {
const { width, height } = useVideoConfig();
const ref = useRef<HTMLCanvasElement>(null);
 
return (
<Gif
ref={ref}
src="https://media.giphy.com/media/3o72F7YT6s0EMFI0Za/giphy.gif"
width={width}
height={height}
fit="fill"
playbackRate={2}
/>
);
};

See also