-
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
Using Gatsby Image with Picture tag? #7313
Comments
gatsby-image doesn't support "art direction" images like this as it seemed like it might overly complicate the API so I left it out. If you can come up with a nice API, I'd love to explore adding it. Otherwise, your approach looks great! Except, make sure to query |
Hey @KyleAMathews the current way I showed above is wrong as I was not using And AFAIK Currently, I am doing: <picture>
<source
media="(max-width: 560px)"
src={data.mobile.childImageSharp.fluid.src}
srcSet={data.mobile.childImageSharp.fluid.srcSet}
/>
<source
media="(max-width: 875px)"
src={data.tablet.childImageSharp.fluid.src}
srcSet={data.tablet.childImageSharp.fluid.srcSet}
/>
<CustomImg fluid={data.desktop.childImageSharp.fluid} />
</picture> where my const CustomImg = styled(Img)`
width: 5rem;
`; The issue is I cannot show Mobile or Tablet images because of that. Only Desktop Image shows up even when screen is reduced. What's the workaround? I can only see 1 workaround like having 3 tags const DesktopImg = styled(Img)`
width: 90rem;
height: 70rem;
@media screen and (max-width: 875px) {
display: none;
}
`;
const TabletImg = styled(Img)`
@media screen and (max-width: 875px) {
width: 70rem;
height: 80rem;
}
@media screen and (max-width: 560px) {
display: none;
}
`;
const MobileImg = styled(Img)`
@media screen and (max-width: 560px) {
width: 50rem;
height: 75rem;
}
`;
<MobileImg fluid={data.mobile.childImageSharp.fluid} />
<TabletImg fluid={data.tablet.childImageSharp.fluid} />
<DesktopImg fluid={data.desktop.childImageSharp.fluid} /> And this works. But this defeats the purpose of Gatsby by downloading images that are not needed at all. Like I don't need Desktop images while visiting from Mobile. I think this should be really implemented into Gatsby because |
Summary
I want to use
gatsby-image
with thepicture
tag. I need to usepicture
tag because I have different images for mobile, tablet & desktop resolutions.Relevant information
This is the current way I do it. Is this the right approach?
Because its used like this in the docs & I don't know if the method above is right
I need 2 things from what I'm doing:
Is it right what I'm doing or is there another approach?
The text was updated successfully, but these errors were encountered: