Skip to content

Commit

Permalink
feat(images): Add small snippet about the inferRemoteSize function (#…
Browse files Browse the repository at this point in the history
…8808)

Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
Princesseuh and sarah11918 authored Jul 18, 2024
1 parent d07b8b6 commit ec1a023
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/content/docs/en/guides/images.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The format of the `src` value of your image file depends on where your image fil
src="https://example.com/remote-image.jpg"
alt="descriptive text"
width="200"
height="150"
height="150"
/>
```

Expand All @@ -143,7 +143,7 @@ If an image is merely decorative (i.e. doesn't contribute to the understanding o

These properties define the dimensions to use for the image.

When using images in their original aspect ratio, `width` and `height` are optional. These dimensions can be automatically inferred from image files located in `src/` and from remote images with [`inferSize` set to `true`](#infersize).
When using images in their original aspect ratio, `width` and `height` are optional. These dimensions can be automatically inferred from image files located in `src/`. For remote images, add [the `inferSize` attribute set to `true`](#infersize) on the `<Image />` or `<Picture />` component or use [`inferRemoteSize()` function](#inferremotesize).

However, both of these properties are required for images stored in your `public/` folder as Astro is unable to analyze these files.

Expand Down Expand Up @@ -266,6 +266,17 @@ import { Image } from 'astro:assets';

`inferSize` can fetch the dimensions of a [remote image from a domain that has not been authorized](#authorizing-remote-images), however the image itself will remain unprocessed.

###### inferRemoteSize()

<p><Since v="4.12.0" /></p>

A function to infer the dimensions of remote images. This can be used as an alternative to passing the `inferSize` property.

```ts
import { inferRemoteSize } from 'astro:assets';
const {width, height} = await inferRemoteSize("https://example.com/cat.png");
```

##### Additional properties

In addition to the properties above, the `<Image />` component accepts all properties accepted by the HTML `<img>` tag.
Expand Down Expand Up @@ -742,4 +753,4 @@ export default defineConfig({

## Community Integrations

There are several third-party [community image integrations](https://astro.build/integrations?search=images) for optimizing and working with images in your Astro project.
There are several third-party [community image integrations](https://astro.build/integrations?search=images) for optimizing and working with images in your Astro project.

0 comments on commit ec1a023

Please sign in to comment.