> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# `<image>`

Displays a PNG, JPEG, WebP, GIF or BMP image, like an `<img>`. It loads bundled assets, remote URLs and base64 data URIs.


## Usage

```typescript title="src/app/avatar.ts"
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import logo from '../assets/logo.png';

@Component({
  selector: 'app-avatar',
  imports: [LYNX_ELEMENTS],
  template: `
    <image [src]="logo" mode="aspectFit" style="width: 64px; height: 64px;" />
    <image
      src="https://example.com/photo.jpg"
      mode="aspectFill"
      style="width: 200px; height: 150px;"
      (binderror)="failed.set(true)"
    />
  `,
})
export class Avatar {
  readonly logo = logo;
  readonly failed = signal(false);
}
```

Import `LYNX_ELEMENTS` in your component (see [Elements](/api/angular-lynx/elements/index.md)).

:::warning
Give every `<image>` a width and height, or `auto-size`. Unlike `<img>`, it has no size of its own, and Lynx doesn't load an image whose box is 0×0. An `<img>` in a template renders as an `<image auto-size>`.
:::

:::info
On an Android phone with 16 KB memory pages:

- a GIF or animated WebP shows its first frame, and sends no `bindstartplay` or loop events
- `blur-radius` ends the app

Lynx's image service is built against Fresco 2.3, whose native libraries for those don't load with 16 KB pages. Phones with 4 KB pages, almost all of them today, animate and blur as usual.
:::

## Attributes

| Attribute                           | Type                                                       | Default         | Description                                                                                                                                                                          |
| ----------------------------------- | ---------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `src`                               | `string`                                                   | —               | Image to show: an imported asset, an `http`/`https` URL or a base64 data URI. SVG doesn't work here: use [`<svg>`](/api/elements/svg.md).                                            |
| `mode`                              | `'scaleToFill' \| 'aspectFit' \| 'aspectFill' \| 'center'` | `'scaleToFill'` | How the image fills its box: stretched, fitted inside (like `object-fit: contain`), covering it (like `cover`), or not scaled. Set it on every image: CSS `object-fit` doesn't work. |
| `placeholder`                       | `string`                                                   | —               | Image shown while `src` loads. Takes the same values as `src`.                                                                                                                       |
| `auto-size`                         | `boolean`                                                  | `false`         | After loading, an image missing a width or height sizes itself to keep the image's aspect ratio.                                                                                     |
| `blur-radius`                       | `string`                                                   | —               | Blurs the image itself, e.g. `'10px'`. To blur what's behind an element, use [`<blur-view>`](/api/elements/blur-view.md).                                                            |
| `tint-color`                        | `string`                                                   | —               | iOS and Android. Paints every non-transparent pixel this color, for single-color icons.                                                                                              |
| `cap-insets`                        | `string`                                                   | —               | iOS and Android. Nine-slice stretching: four insets (top, right, bottom, left) that keep their size while the middle stretches.                                                      |
| `cap-insets-scale`                  | `number`                                                   | `1`             | iOS and Android. Scales the `cap-insets` values.                                                                                                                                     |
| `autoplay`                          | `boolean`                                                  | `true`          | iOS and Android. Starts an animated image as soon as it loads.                                                                                                                       |
| `loop-count`                        | `number`                                                   | `0`             | iOS and Android. How many times an animated image plays. `0` loops forever.                                                                                                          |
| `defer-src-invalidation`            | `boolean`                                                  | `false`         | iOS and Android. Keeps showing the old image until a new `src` has loaded, so there's no blank flash.                                                                                |
| `prefetch-width`, `prefetch-height` | `string`                                                   | `'0px'`         | iOS and Android. Loads the image even while its box is still 0×0. Lynx marks these as deprecated.                                                                                    |
| `image-config`                      | `'ARGB_8888' \| 'RGB_565'`                                 | `'ARGB_8888'`   | Android only. `'RGB_565'` uses half the memory but drops transparency.                                                                                                               |

Plus the [common attributes](/api/elements/view.md#attributes), such as `id`, `class` and `style`.

## Events

Read the payload from `$event.detail`. Angular types `$event` for each event: see [Element events](/api/angular-lynx/element-events.md#image-and-svg).

| Event                     | `detail`                                                                | Description                                                                                     |
| ------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `bindload`                | `{ width: number; height: number }`                                     | The image loaded. The sizes are the image's own, in pixels.                                     |
| `binderror`               | `{ errMsg: string; error_code: number; lynx_categorized_code: number }` | The image failed to load.                                                                       |
| `bindstartplay`           | —                                                                       | iOS and Android. An animated image starts playing.                                              |
| `bindcurrentloopcomplete` | —                                                                       | iOS and Android. An animated image finished one loop.                                           |
| `bindfinalloopcomplete`   | —                                                                       | iOS and Android. An animated image finished all its loops. It never fires without `loop-count`. |

Plus the [common events](/api/elements/view.md#events), such as `bindtap`.

## Methods

These **UI methods** ([Glossary](/guide/glossary.md#ui-method)) control animated images on iOS and Android. Call them with `invoke()` on the element (see [Call element methods](/guide/selector-query.md)).

| Method            | Parameters | Description                                                               |
| ----------------- | ---------- | ------------------------------------------------------------------------- |
| `pauseAnimation`  | —          | Pauses the animation and keeps its loop count.                            |
| `resumeAnimation` | —          | Resumes a paused animation.                                               |
| `stopAnimation`   | —          | Stops the animation and resets its loop count.                            |
| `startAnimate`    | —          | Deprecated. Restarts the animation from the start: use `resumeAnimation`. |

```typescript
import { Component, ElementRef, viewChild } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-spinner',
  imports: [LYNX_ELEMENTS],
  template: `
    <image
      #spinner
      src="https://example.com/spinner.gif"
      style="width: 48px; height: 48px;"
      (bindtap)="pause()"
    />
  `,
})
export class Spinner {
  readonly spinner = viewChild.required('spinner', { read: ElementRef });

  pause(): void {
    this.spinner().nativeElement.invoke?.('pauseAnimation');
  }
}
```

## Related

- [`<svg>`](/api/elements/svg.md): vector images
- [CSS on Lynx](/guide/styling/index.md): sizing, borders and `background-image`
- [Call element methods](/guide/selector-query.md)
