Skip to contentView the source on GitHub

require-image-dimensions

Require dimensions for public and remote astro:assets images.

Performancewarning by default ESLint rule

astro-doctor/require-image-dimensions

Why it matters

Astro can infer dimensions for imported images from src/, but it cannot analyze files served from public/ and needs dimensions or enabled inferSize for remote images. Aliased Image and Picture imports from astro:assets are recognized; unrelated components are ignored. Missing dimensions can cause layout shift while the image loads.

See the difference

Incorrect

Public image without dimensions

astroIncorrect example
---
import { Image } from 'astro:assets'
---
<Image src="/hero.png" alt="Hero image" />

Correct

Public image with dimensions

astroCorrect example
---
import { Image } from 'astro:assets'
---
<Image src="/hero.png" alt="Hero image" width="1200" height="630" />

<Image src="https://cdn.example.com/hero.png" alt="Hero image" inferSize />

Configure this check

Override the default severity in your ESLint config:

javascripteslint.config.js
import astroDoctorPlugin from '@santi020k/eslint-plugin-astro-doctor'

export default [
  astroDoctorPlugin.configs.recommended,
  {
    rules: {
      'astro-doctor/require-image-dimensions': 'error',
    },
  },
]

Or set the severity for CLI scans in doctor.config.ts:

typescriptdoctor.config.ts
export default {
  rules: {
    'astro-doctor/require-image-dimensions': 'error',
  },
}

Use 'error', 'warn', or 'off'. The configuration guide covers presets and per-file overrides.

Keep exploring performance

Browse every rule and project audit