I am struggling with Gatsby-image to provide the right image size to different resolution. I have an image of size 1920x367 (width x height) and the issue is visible when window size is small (mobile for example) because gatsy-image is using an image of 490x92 to cover a container of 437x354.
Here you can see the image when window size is big. Here when window size is low.
GraphQL query:
configHowWeWork: file(relativePath: { eq: "howwework/howwework-header.jpg" }) {
childImageSharp {
fluid(maxWidth: 1920, maxHeight: 367) {
...GatsbyImageSharpFluid_withWebp
}
}
}
Gatsby-image:
<div className="intro intro-page intro-container">
{configHowWeWork.childImageSharp.fluid && (
<Img
className="intro-background"
fluid={configHowWeWork.childImageSharp.fluid}
alt="alt"
/>
)}
</div>
Relevant CSS:
.intro-container {
position: relative;
}
.intro-background {
position: absolute!important;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
left: 0;
top: 0;
z-index: 0;
overflow: hidden;
}
Question: How can I avoid to request an image of size 490x92 (same initial aspect ratio) and instead provide one that can fill up 437x354 (cropping or clipping is what I want, but without zooming in) without streching height.
What I already tried:
- I tried to use FILL as fit in gatsby query to overcome aspect ratio constraint, but it did not the trick.
- Using presentationSize.
Thanks for you answer.
EDIT: THe only one solution found is to create a square image with dimension max(width, height)
, but in my case is always width. In this way I achieve good quality with low and high resolution (mobile and desktop, for example), but I am wasting too much resource:
- With a desktop resolution image generated is 1920x1920, but container dimension is 1920x367.
- With a mobile resolution is not so unbalanced, but still bigger the necessary with height.
I am sure I am missing something because could not be so difficult to just create a responsive wide hero image.
EDIT 2: I can not get why image quality is good if I switch to mobile resolution with Responsive Design Mode in Firefox, but quality is not good if I use a resolution comparable to previous mobile but without Responsive Design Mode.