# image

Draws the image or video unchanged, as a GL copy that page flights and other effects build on.

Looks exactly like the element: the same object-fit, object-position, border-radius and clipping. It is what a keyed image flies as between pages.

Module `media`, category Photo. Import `@dioramajs/media/image`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/media/src/image.ts)

A photo of a brass astrolabe whose frame switches between full, card, round and contained, with the drawn copy following each change.

```html title="index.html"
<img class="astrolabe" src="/media/portfolio/astrolabe.webp" alt="A brass astrolabe of 1462, its star map cut in fine tracery" width="1400" height="933" data-dio="image" />
```

## Usage

Put it on: img, video.

`start()` registers `image`, so the attribute alone puts it on an element.

```html
<img src="/photo.avif" alt="" data-dio="image" />
```

In page transitions: Fades with the page transition.

## Params

It has no params.

## Inputs and frames

Draws only when you scroll, move the pointer over it or change a param. Only when the layout or the picture changes; none at rest. A playing video draws its frames. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. Unchanged, it does not move.

Runs on every device. The same as with a mouse.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { image: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 0.2 KB the first time a page uses it. GPU: One textured quad. Memory: One texture the size of the decoded picture.

See [the quality plugin](/docs/effects/quality).

## Recipes

### Fly a thumbnail to its page

Give the thumbnail on the list page and the cover on the project page the same `data-dio-key`. The thumbnail needs a drawn copy to fly, and `image` gives it one without changing how it looks. The cover may carry another effect, such as `ripple`, and the copy lands into it.

```html title="work.html"
<a href="/work/astrolabe">
  <img
    src="/img/astrolabe-thumb.avif"
    data-dio="image"
    data-dio-key="astrolabe"
  />
</a>
```

```html title="work/astrolabe.html"
<img
  src="/img/astrolabe.avif"
  data-dio="image ripple"
  data-dio-key="astrolabe"
/>
```

### Let every keyed image fly

On a site with many keyed images, attach `image` once from code instead of writing it on each one. The selector skips elements that already carry an effect, since their copy flies anyway.

```ts
import { start } from '@dioramajs/diorama'

const app = start()
app.attach(
  'img[data-dio-key]:not([data-dio]), video[data-dio-key]:not([data-dio])',
  'image',
)
```

### A product film that flies with the page

A playing `<video>` draws each new frame and nothing while it is paused, so a muted loop on a shop card costs a texture upload per frame and no more. With a key it flies to the product page like an image.

```html
<video
  src="/film/lounge.webm"
  poster="/film/lounge.webp"
  muted
  loop
  autoplay
  playsinline
  data-dio="image"
  data-dio-key="lounge"
></video>
```

### Hundreds of tiles that never move

Each drawn frame measures every visible layer. For a large grid of images that move only with the scroll, `data-dio-track="layout"` caches the position at layout changes and subtracts the scroll instead.

```html
<img
  src="/tiles/017.avif"
  data-dio="image"
  data-dio-track="layout"
/>
```

## Notes

The canvas covers the viewport above the page, so a copy draws over any HTML laid on top of its image. Give a caption or button over a drawn image `position: relative` and a `z-index` of 2 or more to keep it in front.

The copy reads `object-fit`, `object-position` and `border-radius` again when the element’s box changes, not in every frame: a style that changes while the box stays the same shows on the copy at its next resize. `none` and `scale-down` draw as `contain`, and corners of different radii draw with the largest one; development builds warn about both.

## Related

- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [compare](/docs/effects/compare.md): Two pictures in one box, before and after, split by a line you drag, hover or scroll.
- [flare](/docs/effects/flare.md): A lens flare or a glossy light sweep over a photo that follows the pointer or the scroll.
- [frost](/docs/effects/frost.md): Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.
- [glitch](/docs/effects/glitch.md): A digital glitch in short bursts: blocks slide sideways, color channels split, scanlines flicker.
- [liquid](/docs/effects/liquid.md): The pointer leaves a fluid trail on a photo that settles back like water.
- [parallax](/docs/effects/parallax.md): The image drifts inside its frame with the pointer and the scroll; with a depth map, in 2.5D.
- [pixelate](/docs/effects/pixelate.md): The image resolves from big pixels to sharp as it scrolls into view, or breaks into pixels on hover.
- [Fly between pages](/docs/learn/flights.md)
- [Page transitions with routers](/docs/guides/routers.md)
- [Performance and quality](/docs/guides/performance.md)
