-
Notifications
You must be signed in to change notification settings - Fork 60
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
SanityImageAsset options aren't passed to Gatsby-Plugin-Image #213
Comments
just noticed this as I wanted to upgrade quality of images on my sites, is there a workaround? |
@RitaDias , @kmelve Corey's |
There is a lot of open issues that have this a their topic. I assume this by design according to #134 (comment) . A temporary brute-force workaround for people in a hurry: You could modify the An example for const breakPointImagesArray = image.breakpointImages && [
...image.breakpointImages.map(artDirectionImage => {
if (
artDirectionImage.breakpoint === "undefined" ||
artDirectionImage.image === "undefined"
) {
throw new Error("Error: ArtDirectionImage incomplete!")
}
return {
media: `(min-width: ${artDirectionImage.minWidth}px)`,
image: getImage(artDirectionImage.image?.asset.gatsbyImageData)
}
})
]
let artDirectionImages = withArtDirection(
getImage(image.defaultImage.asset?.gatsbyImageData),
breakPointImagesArray
)
// Map over the sources and update the srcSet values to improve quality by lowering the breakpoints where images are used
const improvedSources = artDirectionImages.images.sources.map(source => {
const adaptedSrcSet = source.srcSet.replace(/(\d+w)/g, (match, p1) => {
// Divide the width by 2 to improve the quality
const newValue = parseInt(p1) / 2
return `${newValue}w`
})
// Return the updated source object with the new srcSet value
return {
...source,
srcSet: adaptedSrcSet
}
})
// Update the artDirectionImages object with the improved quality sources
let artDirectionImagesImprovedQuality = {
...artDirectionImages,
images: {
...artDirectionImages.images,
sources: improvedSources
}
}
(just an example, another one would be of course to double the width and height parameter values) |
Hi all, Once more thanks! |
We are using Gatsby 3.0 (with
gatsby-plugin-image > 1.5.0
andgatsby-source-sanity > 7.0.4
) on Sanity2.12.2
. Due to our architecture, we need to stick withgatsby-plugin-image
and cannot usegatsby-plugin-sanity-image
.While the images are displayed correctly, we cannot control them using
gatsbyImageData
props listed in gatsby-plugin-image's documentation: they're ignored by Sanity. Only afallbacks
object is returned with ansrc
andsrcSet
, which has all the pixel densities and resolutions already hardcoded. The options likequality
,breakpoints
oroutputPixelDensities
don't work whether they're passed through a GraphQL query or adefaults
object.To quote the docs:
Using the GraphiQL
gatsbyImageData
on aSanityImageAsset
allows to make a basic query, but again, the props listed above do not change what is being returned from Sanity. Some of them, likequality
, are not even listed as possible.I double-checked, the graphql for a given dataset was deployed correctly. It's also not a matter of the plugin versions, as upgrades to the latest don't help.
To Reproduce
Steps to reproduce the behavior:
gatsby-plugin-image
andgatsby-source-sanity
.gatsby develop
http://localhost:8000/___graphiql
gatsbyImageAsset
therebreakpoints
orquality
Expected behavior
gatsbyImageData
has access to all the https://www.sanity.io/docs/image-urls props on Sanity Image.Using them changes the output of the query.
Query Example
Results in:
Which versions of Sanity are you using?
What operating system are you using?
Ubuntu 20.04.2 LTS
Which versions of Node.js / npm are you running?
6.14.4
v12.18.0
The text was updated successfully, but these errors were encountered: