🎥 Make videos programmatically with React
better documentation for <Img>
Jonny Burger71bdfb7320a4
diff --git a/packages/docs/docs/img.md b/packages/docs/docs/img.mdindex 89c61c0c1d..1a68ca706f 100644--- a/packages/docs/docs/img.md+++ b/packages/docs/docs/img.md@@ -3,20 +3,69 @@ title: <Img>id: img----The `<Img />` can be used like a regular `<img>` HTML tag.-The difference is that if you use the component from Remotion, that Remotion will ensure that the image is loaded before rendering the frame. That way you can avoid flickers if it happens that the image is still loading during rendering.+The `<Img />` tag can be used like a regular `<img>` HTML tag.-## Example+If you use `<Img>`, Remotion will ensure that the image is loaded before rendering the frame. That way you can avoid flickers if the image does not load immediately during rendering.++## API++### `src`++[Put an image into the `public/` folder](/docs/assets) and use [`staticFile()`](/docs/staticfile) to reference it.```tsx twoslash-import { Img } from "remotion";-import hi from "./hi.png";+import { AbsoluteFill, Img, staticFile } from "remotion";export const MyComp: React.FC = () => {- return <Img src={hi} />;+ return (+ <AbsoluteFill>+ <Img src={staticFile("hi.png")} />+ </AbsoluteFill>+ );};```+You can also load a remote image:++```tsx twoslash+import { AbsoluteFill, Img } from "remotion";++export const MyComp: React.FC = () => {+ return (+ <AbsoluteFill>+ <Img src={"https://picsum.photos/200/300"} />+ </AbsoluteFill>+ );+};+```++### `onError`++To use the `<Img>` tag in a resilient way, handle the error that occurs when an image can not be loaded:++```tsx twoslash+import { AbsoluteFill, Img, staticFile } from "remotion";++export const MyComp: React.FC = () => {+ return (+ <AbsoluteFill>+ <Img+ src={staticFile("hi.png")}+ onError={(event) => {+ // Handle image loading error here+ }}+ />+ </AbsoluteFill>+ );+};+```++If an error occurs, the component must be unmounted or the `src` must be replaced, otherwise the render will time out.++## Other props++Remotion inherits the props of the regular `<img>` tag, like for example `style`.+## GIFsDon't use the `<Img>` tag for GIFs, use [`@remotion/gif`](/docs/gif) instead.