Skip to content

getImage() silently fails to resize/crop images #13995

@ericswpark

Description

@ericswpark

Astro Info

Astro                    v5.10.0
Node                     v24.2.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

N/A

Describe the Bug

If you define the width and height option inside getImage(options) that do not match the original image's dimensions, then getImage() will just silently ignore the height prop.

Since cropping to fit-center may not be the desired outcome, this makes sense, but then Astro should warn that the input image's aspect ratio does not match that of the specified options.

Example:

// Import someImage that is 3:2 (300 x 200)
import someImage from '@/assets/someImage.png';

// Attempt to resize it to 3:1 (30:10)
const resizedImage = await getImage({
  src: someImage,
  width: 30,
  height: 10,
});

/* getImage() respects the `width` option and scales the image down, but ignores `height`, resulting in a 30x20 image */

What's the expected result?

Show a warning (or error, severity configurable in Astro settings?) if the image aspect ratio does not match when using getImage() and it appears that the user is attempting to crop the image

Link to Minimal Reproducible Example

N/A, StackBlitz doesn't allow image uploads without a paid membership. See above for reproducible code snippet

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P2: nice to haveNot breaking anything but nice to have (priority)feat: assetsRelated to the Assets feature (scope)requires breaking changeFixing this bug or adding this feature would require breaking changes. For PRs, use "semver: major"

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions