Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/images.md
1---2name: images3description: Embedding images in Remotion using the <Img> component4metadata:5tags: images, img, staticFile, png, jpg, svg, webp6---78# Using images in Remotion910## The `<Img>` component1112Always use the `<Img>` component from `remotion` to display images:1314```tsx15import { Img, staticFile } from "remotion";1617export const MyComposition = () => {18return <Img src={staticFile("photo.png")} />;19};20```2122## Important restrictions2324**You MUST use the `<Img>` component from `remotion`.** Do not use:2526- Native HTML `<img>` elements27- Next.js `<Image>` component28- CSS `background-image`2930The `<Img>` component ensures images are fully loaded before rendering, preventing flickering and blank frames during video export.3132## Local images with staticFile()3334Place images in the `public/` folder and use `staticFile()` to reference them:3536```37my-video/38├─ public/39│ ├─ logo.png40│ ├─ avatar.jpg41│ └─ icon.svg42├─ src/43├─ package.json44```4546```tsx47import { Img, staticFile } from "remotion";4849<Img src={staticFile("logo.png")} />;50```5152## Remote images5354Remote URLs can be used directly without `staticFile()`:5556```tsx57<Img src="https://example.com/image.png" />58```5960Ensure remote images have CORS enabled.6162For animated GIFs, use the `<Gif>` component from `@remotion/gif` instead.6364## Sizing and positioning6566Use the `style` prop to control size and position:6768```tsx69<Img70src={staticFile("photo.png")}71style={{72width: 500,73height: 300,74position: "absolute",75top: 100,76left: 50,77objectFit: "cover",78}}79/>80```8182## Dynamic image paths8384Use template literals for dynamic file references:8586```tsx87import { Img, staticFile, useCurrentFrame } from "remotion";8889const frame = useCurrentFrame();9091// Image sequence92<Img src={staticFile(`frames/frame${frame}.png`)} />9394// Selecting based on props95<Img src={staticFile(`avatars/${props.userId}.png`)} />9697// Conditional images98<Img src={staticFile(`icons/${isActive ? "active" : "inactive"}.svg`)} />99```100101This pattern is useful for:102103- Image sequences (frame-by-frame animations)104- User-specific avatars or profile images105- Theme-based icons106- State-dependent graphics107108## Getting image dimensions109110Use `getImageDimensions()` to get the dimensions of an image:111112```tsx113import { getImageDimensions, staticFile } from "remotion";114115const { width, height } = await getImageDimensions(staticFile("photo.png"));116```117118This is useful for calculating aspect ratios or sizing compositions:119120```tsx121import {122getImageDimensions,123staticFile,124CalculateMetadataFunction,125} from "remotion";126127const calculateMetadata: CalculateMetadataFunction = async () => {128const { width, height } = await getImageDimensions(staticFile("photo.png"));129return {130width,131height,132};133};134```135