Replies: 5 comments 11 replies
-
I'm still in two minds as to whether having formats as an array if a good idea or not. My concern is whether peopel will be confused and end up have it convern all the JPEGs to PNGs or something equally bad. However it is the most flexible way, and most people could leave it as the default ( |
Beta Was this translation helpful? Give feedback.
-
+1 for simplifying the GraphQL pattern and providing a Concerning the options I would appreciate if a new API would transparently pass through to the actual sharp options wherever possible from a functional perspective (plugin config, component props, docs, etc). That means to neither redefine, rename, validate or separately document them at all. I spent too much time digging the gatsby repository trying to find out what exactly is going on with an option. For example, Since the option values are not abstracting from the underlying library's interpretation of an option's value anyways I think it would be better practice to be transparent and explicit in passing through. |
Beta Was this translation helpful? Give feedback.
-
(Separate comment because it's a likely controversial topic - but introducing a new breaking API is the seldom opportunity to at least reconsider previous decisions) Placeholders and fade-in animations are an opinionated UX choice that was popularized by medium.com but have to my observation not become a de facto standard UX across the web. There are valid pro and contra arguments and many like the effect but the pros and the "popular vote" are not strong enough to me to want a site generator framework apply end user visible animations to all images as a default, esp. given that it happens at the cost of significant build performance and potential frontend performance. I suggest to consider changing the defaults to NONE (placeholders) and 0ms (animation). |
Beta Was this translation helpful? Give feedback.
-
Currently I'm thinking of moving |
Beta Was this translation helpful? Give feedback.
-
Adding |
Beta Was this translation helpful? Give feedback.
-
For the latest on the new image plugin, see #27950
Original RFC below
We are currently working on a new image plugin to replace gatsby-image, which greatly improves performance (Lighthouse 💯 again) and adds easy static images (no GraphQL). Part of it is also a new, simpler API for gatsby-transformer-sharp. This RFC is to discuss a proposal for this API. You can take a look at the branch here: #27443
Background
There are two new components that will use this API,
GatsbyImage
andStaticImage
.GatsbyImage
This component will be used for all of your dynamic images, such as the ones coming from a CMS or Markdown. Just like the current
gatsby-image
component, you will query the data using GraphQL. However the API for this is a bit different, and should be simpler. There are no more fragments, with the options passed as arguments to the resolver instead, and the data is returned as a JSON object rather than individual fields. You should treat this image data as an opaque object, and pass it directly to the component. The syntax is like this:...and the data is passed to the new component like this:
(
getImage
is a simple helper that takes a file node and returnsfile?.childImageSharp?.gatsbyImage?.imageData
. It is not required, but saves typing)As shown above, the options are passed as arguments to the resolver, rather than using fragments. Many of these options are likely to match those used by the current
fixed()
andfluid()
resolvers, but there are some new ones.StaticImage
This is a simpler component for static images, where the
src
is known at compile time. The API is similar, but the options are passed as props to the component:Image API
These are the proposed options, which would either be passed to the GraphQL resolver or as props to the component. Most of these would be optional, and most people wouldn't need to use them. They are slightly different from the ones currently implemented in the alpha. We would welcome feedback on the API.
FIXED
: A static image that does not resize according to the screen widthFLUID
: The image resizes to fit its container. Pass a "sizes" option if it isn't going to be the full width of the screen.CONSTRAINED
: Resizes to fit its container, up to a maximum width, at which point it will remain fixed in size.DOMINANT_COLOR
: a solid color, calculated from the dominant color of the image.BLURRED
: a blurred, low resolution image, encoded as a base64 data URI (equivalent to current "base64" option)TRACED_SVG
: a low-resolution traced SVG of the image.NONE
: no placeholder. Set "background" to use a fixed background color.AUTO
(output the same format as the source image),JPG
,PNG
orWEBP
. Default is[AUTO, WEBP]
meaning it will generate images in the same format as the source, as well as in WebP. Coming soon:AVIF
...?![ 1, 2 ]
for fixed images, meaning 1x, 2x and[0.25, 0.5, 1, 2]
for fluid. In this case, an image with a fluid layout and width = 400 would generate images at 100, 200, 400 and 800px wide•
fixed
: "width px"•
fluid
: "100vw"•
constrained
: "(min-width: width px) width px, 100vw"FLUID
orCONSTRAINED
. For other layout types, use "width"FLUID
orCONSTRAINED
, where you should use "maxWidth" instead.TRACED_SVG
, these options are passed to potracewidth
(size of the low-res preview. Default 20px),format
(force the output format, rather than using the same as the source image)COVER
,CONTAIN
,FILL
,INSIDE
,OUTSIDE
. See Sharp’s resize.CENTER
,NORTH
,NORTHEAST
,EAST
,SOUTHEAST
,SOUTH
,SOUTHWEST
,WEST
,NORTHWEST
,ENTROPY
,ATTENTION
. See Sharp’s resize.DOMINANT_COLOR
for the placeholder then it will be chosen for youshadow
andhighlight
defining start and end color of the duotone gradientThese API options are not decided, and so we welcome your feedback on how you would use them.
Beta Was this translation helpful? Give feedback.
All reactions