> From the [Strife developer docs](https://strife.app/docs/reference/field-reference/fields.image). Every page is listed in [llms.txt](https://strife.app/docs/llms.txt).

# fields.image()

Single image upload with required dimension and format hints.

Single image upload. Maps to editor `{ name: 'str-image', type: 'image' }`. Output is the canonical `Image` from `@strifeapp/types`. `width`/`height`/`format` are dimension/transform hints baked into the template. An editor can still choose **Fit** for an image, which keeps the whole picture inside the output box instead of cropping it.

## Example

```ts
fields.image({
  label: 'Cover image',
  localizable: false,
  width: 1600,
  height: 900,
  format: 'webp',
})

// Responsive: Strife stores a srcset with widths up to 2880px
fields.image({
  label: 'Hero',
  width: 2880,
  height: 1920,
  format: 'avif',
  widths: 'auto',
})

fields.image({
  label: 'Logo',
  width: 400,
  height: 'auto',
  format: 'png',
})
```

## Options

| Option         | Type              | Required | Description                                                                                                                        |
| -------------- | ------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `label`        | `string`          | Yes      | Label shown to editors in Strife Studio.                                                                                          |
| `width`        | `number`          | Yes      | Target width hint used for image transforms.                                                                                      |
| `height`       | `number \| 'auto'` | Yes      | Target height hint, or `'auto'` for a width-only image that keeps the source aspect ratio (crop/zoom are disabled in the editor). |
| `format`       | `ImageFormat`     | Yes      | Target output format — one of `jpeg`, `png`, `webp`, `svg`, `gif`, `avif`, `ico`, `heic`, `tif`, `bmp`.                           |
| `widths`       | `number[] \| 'auto'` | No    | Responsive widths. When set, the image's value gets a `source.srcset` to use in `<img srcset>`. `'auto'` is about 25 % steps from 320px up to `width`; an array is exactly these widths (16–4096, at most 12). Never larger than `width` or the original. See [Responsive images](https://strife.app/docs/how-to-guides/responsive-images.md). |
| `localizable`  | `boolean`         | No       | When `true`, output is `Record<string, Image>` instead of `Image`.                                                                |
| `propertyName` | `string`          | No       | Override the stored property name.                                                                                                |
| `hideAlt`      | `boolean`         | No       | Hide the alt-text input in the editor.                                                                                            |

> [!NOTE]
> `height: 'auto'` is DSL-only sugar — the compiled template JSON always stores a plain number, with `0` as the width-only convention (`height === 'auto' ? 0 : height`). [Image](https://strife.app/docs/reference/fields/image.md) documents the same `0`-means-width-only convention from the Strife Studio / raw-JSON side.

## Output type

`Image`, or `Record<string, Image>` when `localizable: true`.

With `widths`, `source.srcset` holds a ready `srcset` attribute value (`"https://… 320w, https://… 400w, …"`), so it goes straight into your markup:

```astro
<img
  src={image.source.url}
  srcset={image.source.srcset}
  sizes="auto"
  loading="lazy"
  width={image.width}
  height={image.height}
  alt={image.alt}
/>
```

Strife writes the srcset when an editor picks or crops the image in Strife Studio. It is absent on images saved before you added `widths`, on SVG and GIF images, and on images written through the API; `src` alone still works. `source.placeholder` holds the image's average color (`#rrggbb`) for a background while it loads. `widths` needs `@strifeapp/strife` 1.20.0 or later, which brings `@strifeapp/schema` 0.17.0.

## See also

* [Image](https://strife.app/docs/reference/fields/image.md) — the same editor, documented from the Strife Studio UI side.
* [`fields.imageGroup()`](https://strife.app/docs/reference/field-reference/fields.imagegroup.md) — multiple named image slots in one field.
* [Responsive images](https://strife.app/docs/how-to-guides/responsive-images.md) — `srcset` and `sizes` for heroes, content images, card grids and fixed-size images.
