-
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] [gatsby-transformer-sharp] Emulate <img srcSet> behavior (restrict 2x images to 1x width) #9804
[gatsby-image] [gatsby-transformer-sharp] Emulate <img srcSet> behavior (restrict 2x images to 1x width) #9804
Comments
Hey! This is exactly how gatsby-image works! Checkout https://using-gatsby-image.gatsbyjs.org and https://using-wordpress.gatsbyjs.org/sample-post-1 to see how you can do image processing with gatsby and WordPress. Wp example site link https://github.com/gatsbyjs/gatsby/tree/master/examples/using-wordpress |
@KyleAMathews Thanks for weighing in. I think I must still be missing something. In my repro repo, you'll notice what …thus being shown at lower than full-resolution, as opposed to Every example I see in the docs has a container to restrict
And the docs mention:
So now I'm leaning that my use-case isn't met, but your 'This is exactly how gatsby-image works!' is making me unsure again—ha. |
Oh used "fixed" not fluid :-) |
Okay, I'll experiment with that more—currently images are rendering with 0 height upon swapping. Thanks for the tip. edit: for anyone following along—i was still using the |
Hm, just updated the repo. Now it is restricted in |
Summary
Relevant information
Prior to using
gatsby-image
, most of my high-resolution image work in markup was via theimg
srcSet
atrribute. Check out this Codepen for a quick demo. Basically, given the following markup:The result will be:
src
image at it's nativewidth
&height
(250px in my example)srcSet
image at half nativewidth
&height
(so still 250px in my example)I'm basically looking to achieve that same behavior with
gatsby-image
: generate a 2x image withgatsby-transformer-sharp
, but don't display it at that 2x size—rather restrict it's size so it's never shown at less than full resolution.I think I'm probably over-thinking or missing something—is this not currently possible with
gastby-image
as-is? (edit: Maybe I'm misunderstanding thefluid
/fixed
split…).If not, I imagine most are achieving this with a container markup/component, but that's not feasible because the app I'm working on—the images are coming from WordPress and a range of sizes.
I've created a repo when I've achieved this functionality, but it's going to take quite a bit of work to update my app to use the solution. Here's the relevant file—note the wrapping div and use of
childImageSharp.fluid.presentationWidth
: https://github.com/dustinhorton/gatsby-issue2/blob/master/src/components/image2.jsThe text was updated successfully, but these errors were encountered: