-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gatsby-image rendering larger than maxWidth (fluid) #15669
Comments
Please check https://www.gatsbyjs.org/packages/gatsby-image/#avoiding-stretched-images-using-the-fluid-type We don't limit width by default - there is the need of user choice in how to layout images that are narrower than container (should they be center, left-aligned, right-aligned). It also might be desired not to limit width in cases like hero images or other full-viewport width images and it's easier to use |
hi, I'm sorry @pieh but I'm totally unable to understand all how this works after reading the doc. What I can tell is:
Is there a way to ensure that no matter what we only use an image of width === 1000? I don't understand the things about streching images. I'm just using object-fit so I don't understand how I could be concerned by this. It's totally possible to display a smaller image in a large container and yet preserve image ratio. I have a fluid hero image, the container might be 4000px, yet I still want to limit the image displayed inside this container to be max width = 1000px, even if quality is not good, it's my own problem. Can you please tell me what I can do to really put a threshold of 1000pw on my images? Currently people having large screens are downloading 1.5mo of hero image. The only workaround I see for now is... to actually reduce my original image sizes. That feels wrong no? |
No browser will download the 4000px image — if you have your HTML container set to a |
So, on Twitter @KyleAMathews found I had good arguments (https://twitter.com/gatsbyjs/status/1157067242858614785) I understand the rationale behind always outputting x2 the maxWidth for retina screens, yet there are 2 problems:
Let's consider 2 scenarios to understand better. Both assume my input image is 6000w: 1 small fluid thumbnail where container to width=500
2 large fluid hero image 100vw
This is a big problem for me because this means a large retina screen will download a huge picture and create a lot of work for the browser to resize it, giving bad lighthouse score. I should have control over the output of Gatsby's srcset. In my usecase if user has a retina screen of 2001w, I prefer him to use the 2000w image, not the 6000w image, even if the image won't be as beautiful as least it will be more lightweight. (In my case this hero image is behind a translucide overlay so I don't require extreme quality) ProposalIt would be nice to be able to tell gatsby which is the hard limit for image size width to be in the output resizes/srcset, without loosing the default ability to handle retina screens by default using current x2 strategy. I'm thinking of something like this
|
I think the simplest solution is to only include the original image if it's smaller than 2 * maxWidth. My assumption with the code is that you're always constraining the width of the image but this isn't true with 100vw so we should check the size of the original image before including it in the srcset |
Filtering by 2 * maxWidth would already be nicer yeah, but I would rather give user full control and let him set a hard limit which defaults to filtering on x 2 Yes that's true I may normally not want to a put a maxWidth on my hero images as the width of the container has an unlimited maxWidth. Yet If user has a retina screen of 2000w+ I don't want the srcset to load a 4000 image neither as it's really heavy for both bandwidth and resizing. If screen is retina 2200w I'd rather have the browser download the 2000w version even if this means lower quality (which is fine for my specific usecase). The solution you are proposing does not really permit me to put a hard limit of 2000 in srcset, and I'll have to put 1000 as a workaround for my usecase which is a bit counter intuitive as an API. |
maxWidth is just the max width of screens you care about for the design. Most people don't design past say 1400 px so that's what I'd assume they'd put. We're trying to simplify your life so you don't have to think about different types of screens and image sizes. You just ask for what your design needs. |
Yeah got that but what I'm supposed to do? I want 2000 non retina to get 2000px image, and 2000 retina to also get 2000px image. Current API does not really allow to me tell Gatsby those requirements. I understand your default choices, but it would be cool to be able to override those if they don't make sense for my usecase |
Once we make the change to exclude the original, that's what would happen with a maxWidth of 1000. Browsers would see the max image is 2000 pixels and that the screen width is 2000 and grab the largest. |
Sure, that'll do the job for my case, but still think it's a bit counter intuitive api ;) |
I just ran into this same issue. For me the problem is that the website becomes unfathomably large when unnecessarily large versions of images are generated (I don't know how large; it takes too long to compile). I understand all the arguments regarding high retina displays and letting the browser choose etc. -- but I can't compile my site without resizing images outside Gatsby. How about keep the default behavior as it is and offer users a flag like |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks again for being part of the Gatsby community! |
Is there a plan to exclude the original size? |
Would also greatly appreciate this: getting Lighthouse failures for |
it can be helpful to resize images: https://www.gatsbyjs.com/docs/preoptimizing-images/ |
Description
Gatsby-image is rendering images larger than their maxWidth and Height set in graphql. This is the query I've used:
Expected result
I expect the rendered image to not be larger than 1062px in width, nor greater than 723px in height. However, it's rendered at 1168px. The container its in is 1200px in width, so 1168px feels random.
This is what's rendered, which doesn't mention the width of 1168px anywhere 🤔
Environment
The text was updated successfully, but these errors were encountered: