# Image — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/image

Category: Media

renders an image with optional quick placeholder image, background blur, and loader, also dynamically calculates aspect ratio

Public component import: `Image`

Public manager import: `create_image_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Image, create_image_manager } from "sveltekit-ui"

  // Inline artwork keeps this example independent of image hosting.
  const artwork = (sky) => "data:image/svg+xml," + encodeURIComponent(
    '<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360" viewBox="0 0 640 360">' +
    '<rect width="640" height="360" fill="' + sky + '"/>' +
    '<circle cx="500" cy="90" r="42" fill="#fde68a"/>' +
    '<path d="M0 360 190 115 390 360ZM240 360 430 160 640 360Z" fill="#164e63"/></svg>'
  )

  const manager = create_image_manager({
    src: artwork("#bae6fd"),
    alt: "Mountain silhouettes beneath a sunny blue sky",
    image_width: 640,
    image_height: 360,
    border_radius: 1.5,
  })
</script>

<Image {manager} />
```

## Configuration

### `storage_path`

- type: string
- default: null
- description: a template path for retrieving an image by storage_id, e.g. '/api/storage/{storage_id}'

### `selector_id`

- type: string
- default: null
- description: optional identifier for referencing or targeting this image manager

### `bg_img_blur`

- type: number
- default: 0
- description: the background blur radius in pixels for the placeholder image

### `bg_img_opacity`

- type: number
- default: 0
- description: the background image's opacity (often used with blur)

### `alt`

- type: string
- default: null
- description: alt text for the image

### `storage_id`

- type: string
- default: null
- description: storage id to replace in storage_path, if no direct src is provided

### `src`

- type: string
- default: null
- description: the final url for the image; if null, tries to get from storage_path + storage_id

### `storage_id_quick`

- type: string
- default: null
- description: storage id for a quick/placeholder image

### `src_quick`

- type: string
- default: null
- description: a fast-loading low-res or placeholder image displayed behind and during loading

### `image_width`

- type: number
- default: null
- description: the image’s intrinsic width in px if known

### `image_height`

- type: number
- default: null
- description: the image’s intrinsic height in px if known

### `image_aspect_ratio`

- type: number
- default: null
- description: aspect ratio (width / height). if null, calculates once image loads

### `display_max_width`

- type: number
- default: 800
- description: the maximum display width in px

### `display_max_height`

- type: number
- default: 600
- description: the maximum display height in px

### `border_radius`

- type: number
- default: 1
- description: the border radius (in rem) for the container

## Methods

### `handle_mount()`

- description: executes on svelte's onmount hook, checks if images are loaded, and sets their dimension info
- parameters:
- returns: void

## Returned state

### `id`

- type: string
- description: unique internal id for this image instance

### `is_loading_main_image`

- type: boolean
- description: indicates if the main high-res image is still loading

### `selector_id`

- type: string
- description: optional external reference id for the image

### `src`

- type: string
- description: the actual url used for the main image

### `src_quick`

- type: string
- description: url for a quick-loading placeholder image

### `alt`

- type: string
- description: alt text for the image

### `display_max_width`

- type: number
- description: the maximum display width in px

### `display_max_height`

- type: number
- description: the maximum display height in px

### `image_width`

- type: number
- description: the actual image width in px after loading

### `image_height`

- type: number
- description: the actual image height in px after loading

### `image_aspect_ratio`

- type: number
- description: width / height of the image (calculated after load if not provided)

### `bg_img_blur`

- type: number
- description: blur radius in px for the background placeholder

### `bg_img_opacity`

- type: number
- description: opacity for the blurred background

### `bg_img_style`

- type: string
- description: the background property used for the placeholder blur layer

### `border_radius`

- type: number
- description: the border radius in rem for the container
