You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(gatsby-transformer-sharp): add inside and outside fit opt… (#14852)
Added `INSIDE` and `OUTSIDE` options for for gatsby-transformer-sharp. Here's a use case for inside [#13078 (comment)](#13078 (comment)).
This includes changing gatsby-image to use `contain` instead of `cover` for object-fit, which does not affect the existing fit options.
Updated documentation for gatsby-transformer-sharp to clarify the fit options and show that they are available for all three functions.
NOTE: This is an extension of PR #13393 by @VGoose , which was closed because he didn't have time to complete the work.
Co-authored-by: AnhVoMBP15 <[email protected]>
Co-authored-by: soundguy66 <[email protected]>
Co-authored-by: gatsbybot <[email protected]>
Co-authored-by: Ward Peeters <[email protected]>
Read more in the [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/?=#fixed) README.
132
+
Read more about fixed image queries in the [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/#fixed) README.
133
133
134
134
### Images that stretch across a _fluid_ container
135
135
@@ -177,18 +177,17 @@ In a query, you can specify options for fluid images.
177
177
-`maxHeight`(int)
178
178
-`quality` (int, default: 50)
179
179
-`srcSetBreakpoints` (array of int, default: [])
180
-
-`fit` (string, default: `[sharp.fit.cover][6]`)
181
180
-`background` (string, default: `rgba(0,0,0,1)`)
182
181
183
182
#### Returns
184
183
185
184
-`base64` (string)
186
-
-`src` (string)
187
-
-`width` (int)
188
-
-`height` (int)
189
185
-`aspectRatio` (float)
190
186
-`src` (string)
191
187
-`srcSet` (string)
188
+
-`srcSetType` (string)
189
+
-`sizes` (string)
190
+
-`originalImg` (string)
192
191
193
192
This is where fragments like `GatsbyImageSharpFluid` come in handy, as they'll return all the above items in one line without having to type them all out:
Read more in the [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/?=#fluid) README.
206
+
Read more about fluid image queries in the [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/#fluid) README.
208
207
209
208
### Resized images
210
209
@@ -240,15 +239,19 @@ allImageSharp {
240
239
}
241
240
```
242
241
242
+
Read more about resized image queries in the [gatsby-plugin-sharp](/packages/gatsby-plugin-sharp/#resize) README.
243
+
243
244
### Shared query parameters
244
245
245
-
In addition to `gatsby-plugin-sharp` settings in `gatsby-config.js`, there are additional query options that apply to both _fluid_and _fixed_ images:
246
+
In addition to `gatsby-plugin-sharp` settings in `gatsby-config.js`, there are additional query options that apply to _fluid_, _fixed_, and _resized_ images:
Here's an example of using the `duotone` option with a fixed image:
254
257
@@ -286,13 +289,13 @@ fixed(
286
289
<figcaption>Grayscale | Before - After</figcaption>
287
290
</figure>
288
291
289
-
Read more in the [`gatsby-plugin-sharp`](/packages/gatsby-plugin-sharp) README.
292
+
Read more about shared image query parameters in the [`gatsby-plugin-sharp`](/packages/gatsby-plugin-sharp/#shared-options) README.
290
293
291
294
## Image query fragments
292
295
293
296
GraphQL includes a concept called "query fragments", which are a part of a query that can be reused. To ease building with `gatsby-image`, Gatsby image processing plugins which support `gatsby-image` ship with fragments which you can easily include in your queries.
294
297
295
-
> Note: using fragments in your queries depends on which data source(s) you have configured. Read more in the [gatsby-image](/packages/gatsby-image#fragments) README.
298
+
> Note: using fragments in your queries depends on which data source(s) you have configured. Read more about image query fragments in the [gatsby-image](/packages/gatsby-image/#fragments) README.
296
299
297
300
### Common fragments with `gatsby-transformer-sharp`
Copy file name to clipboardExpand all lines: packages/gatsby-plugin-sharp/README.md
+27-8
Original file line number
Diff line number
Diff line change
@@ -101,11 +101,10 @@ a base64 image to use as a placeholder) you need to implement the "blur up"
101
101
technique popularized by Medium and Facebook (and also available as a Gatsby
102
102
plugin for Markdown content as gatsby-remark-images).
103
103
104
-
When both a `maxWidth` and `maxHeight` are provided, sharp will use `COVER` as a fit strategy by default. This might not be ideal so you can now choose between `COVER`, `CONTAIN` and `FILL` as a fit strategy. To see them in action the [CSS property object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) comes close to its implementation.
105
-
106
-
#### Note
107
-
108
-
fit strategies `CONTAIN` and `FILL` will not work when `cropFocus` is assigned to [sharp.strategy][6]. The `cropFocus` option cannot be `ENTROPY` or `ATTENTION`
104
+
When both a `maxWidth` and `maxHeight` are provided, sharp will [resize the image][6] using
105
+
`COVER` as a fit strategy by default. You can choose between `COVER`, `CONTAIN`, `FILL`,
106
+
`INSIDE`, and `OUTSIDE` as a fit strategy. See the [fit parameter below](#fit)
107
+
for more details.
109
108
110
109
#### Parameters
111
110
@@ -116,7 +115,6 @@ fit strategies `CONTAIN` and `FILL` will not work when `cropFocus` is assigned t
- Pixel density is only used in vector images, which Gatsby’s implementation of Sharp doesn’t support. This option is currently a no-op and will be removed in the next major version of Gatsby.
0 commit comments