🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Performance••By Komal Nakrani

Fix: Failed to Retrieve Remote Image Dimensions in Astro

Astro's 'Failed to retrieve remote image dimensions' means inferSize could not fetch the image. Check the URL, import local files, or set width and height.

#Astro#Errors#Images#astro:assets

Astro shows “Failed to retrieve remote image dimensions” when an <Image>, <Picture> or getImage() call uses inferSize and Astro cannot download enough of the image to read its size. The URL is wrong or unreachable, it points at a public/ file instead of a real remote URL, or the server returned an error. Fix the URL, import local images from src/, or drop inferSize and pass width and height yourself.

Key Takeaways

  • inferSize makes Astro fetch the remote image at build or request time to read its size.
  • Any network failure, non-200 response or non-HTTP URL triggers this error.
  • inferSize is for remote URLs only; it does not work with public/ paths like /images/hero.jpg.
  • Local images belong in src/ and should be imported, so Astro knows their size.
  • Explicit width and height avoid the network request entirely.

The error

Failed to retrieve remote image dimensions.
Failed to get the dimensions for https://cdn.example.com/photos/hero.jpg.
Hint: Verify your remote image URL is accurate, and that you are not using `inferSize` with a file located in your `public/` folder.

Why it happens

With inferSize, Astro requests the image and reads its header bytes to find the width and height. It reports this error when:

  1. The src cannot be parsed as a URL, or (with no image domains configured) is not http: or https:.
  2. The request fails: DNS error, timeout, or the server is offline.
  3. The response is not OK, such as a 404 or 403, or has no body.
  4. Redirects loop or exceed the limit.

A path like /images/hero.jpg is not a remote URL. It is a file in public/, and Astro will not fetch it from your own site during the build.

Fix a remote URL

Open the URL in a browser or check it with curl:

# Terminal
curl -I https://cdn.example.com/photos/hero.jpg

You want HTTP/2 200 and an image/* content type. If the CDN blocks requests without a browser user agent or needs a signed URL, Astro’s request will fail too. Also make sure the domain is allowed in image.domains or image.remotePatterns, otherwise you get a remote image not allowed error first.

---
// src/components/Hero.astro
import { Image } from 'astro:assets';
---
<Image src="https://cdn.example.com/photos/hero.jpg" alt="Harbour at dawn" inferSize />

Fix a local image

Move the file from public/ to src/assets/ and import it. Astro reads its dimensions at build time with no network request:

---
// src/components/Hero.astro
import { Image } from 'astro:assets';
import hero from '../assets/hero.jpg';
---
<Image src={hero} alt="Harbour at dawn" />

Fix: set the size yourself

If the remote server is unreliable in CI, skip inferSize and give the dimensions:

<Image
  src="https://cdn.example.com/photos/hero.jpg"
  alt="Harbour at dawn"
  width={1600}
  height={900}
/>

This also makes builds faster, because Astro no longer fetches each image just to measure it. Our image component guide covers inferSize and the other props, the styling docs cover how theme layouts size images, and the official images guide explains remote images in detail. If you are filling a theme with your own photos, the replace theme images tip shows where they go; you can preview each layout’s image slots in the Astro themes catalog.

FAQ

What does inferSize do in Astro?

It tells Astro to fetch a remote image and read its width and height, so you do not have to pass them. It only applies to remote URLs.

Why does inferSize fail only in CI?

The build machine cannot reach the image host, or the host rejects its requests. Test the URL from the CI runner, or pass width and height explicitly.

Can I use inferSize with images in public/?

No. Files in public/ are not fetched during the build. Import the image from src/ instead, or set its dimensions by hand.