unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

feat: default to not upscaling images #41

Closed ascorbic closed 3 years ago

ascorbic commented 3 years ago

This PR changes the default to not return images larger than the source. It adds an enlarge modifier which disables this, and allows larger images to be returned.

The PR also makes two additions: it adds meta to the handler context, so handlers have access to details of the source image. It adds a new clampDimensionsPreservingAspectRatio util. We can't use sharp's withoutEnlargement when specifying both dimensions, because that doesn't preserve the requested aspect ratio. Instead we calculate the dimensions ourselves.

Fixes #39

ascorbic commented 3 years ago

@pi0 Does this look like the right approach to you?

pi0 commented 3 years ago

Released by 0.7.2