Replies: 2 comments
-
Thanks for the feature suggestion. I’ve also heard this sometimes referred to as “cropping support”, i.e. the ability to remove parts of an image or letterbox it if the width/height aspect ratio does not match the source image. Linking this other discussion which seems related: #808 |
Beta Was this translation helpful? Give feedback.
-
Seems to be exactly what Gatsby's Image API has using sharp https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/#all-options aspectRatio transformOptions also seems great: These values are passed in as an object to transformOptions, either as a prop to StaticImage, or to the resolver for dynamic images. They are advanced settings that most people will not need to change. Any provided object is merged with the defaults below. cropFocus fit |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Make it easy to set the aspect ratio with
<Image>
fromastro:assets
.Background & Motivation
AFAICT,
Image
andgetImage
do not support theaspect-ratio
attribute and do not respect theheight
when the user specifies bothwidth
andheight
attributes (it "fails" silently). This situation may lead to some convoluted approaches to get the desired result (bypassing astro image optimization entirely or at least changing manually the aspect ratio of the original image, etc.). Additionally, unless I am mistaken, controlling the aspect-ratio afterwards in HTML is not always possible (when e.g. thesrcset
andsizes
attributes are used ... and that would be more complex anyway, right?).Goals
Integrate the image aspect-ratio transformations into the
astro:assets
pipeline,Support the "classic" resizing options in this process ("cover", "contain", etc.)
Propose a familiar API that extends the current one.
Note that
sharp
already supports the required features.Example
We could obviously copy the HTML syntax (width
width
,height
,aspect-ratio
,object-fit
, etc. attributes).Beta Was this translation helpful? Give feedback.
All reactions