astro:assets module.
Importing
Image Component
The<Image /> component optimizes images and generates responsive image markup.
Props
Image source. Can be an imported image or a URL string.
Alternative text for the image. Required for accessibility.
Desired width of the image. Sets the
width attribute and resizes the image.Desired height of the image. Sets the
height attribute and resizes the image if width is not provided.Output format for the image.Default:
'webp'Quality preset or numeric value (0-100) for the output image.
Pixel densities to generate for the image srcset.
Widths to generate for the image srcset.
How the image should be resized to fit the dimensions.Default:
'cover'Position of the image when using
fit. Similar to CSS object-position.Background color to use when converting transparent images to non-transparent formats.
Automatically infer width and height from the source image.Default:
true for local imagesHTML Attributes
All standard HTML<img> attributes are also supported:
Example
Picture Component
The<Picture /> component generates a <picture> element with multiple sources and formats.
Props
Array of image formats to generate. The component will create a
<source> for each format.Default: ['webp']Format to use for the fallback
<img> element.Default: 'png'Attributes to apply to the
<picture> element.Image component are also supported.
Example
getImage
Programmatically get optimized image data without rendering an<img> tag.
Object containing optimized image data.
URL of the optimized image.
HTML attributes for the image (width, height, etc.).
Processed transformation options.
Example
ImageMetadata Type
Type for imported images.Example
Remote Images
To use remote images, configureimage.domains or image.remotePatterns in your Astro config: