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
Copy file name to clipboardExpand all lines: packages/gatsby-plugin-image/README.md
+11-9
Original file line number
Diff line number
Diff line change
@@ -316,26 +316,28 @@ The optional helper function `getImage` takes a file node and returns `file?.chi
316
316
317
317
These arguments can be passed to the `gatsbyImageData()` resolver:
318
318
319
-
-**width**: The display width of the generated image for layout = FIXED, if layout = CONSTRAINED it's the display width of the largest generated image. The actual largest image resolution will be this value multiplied by the largest value in outputPixelDensities.
320
-
-**height**: If set, the height of the generated image. If omitted, it is calculated from the supplied width, matching the aspect ratio of the source image.
319
+
-**width**: The display width of the generated image for layout = FIXED, if layout = CONSTRAINED it's the maximum display width. Ignored for FULL_WIDTH images.
320
+
-**height**: If set, the height of the generated image. If omitted, it is calculated from the supplied width, matching the aspect ratio of the source image. Ignored for FULL_WIDTH images.
321
+
-**aspectRatio**: Forces an image to the specified aspect ratio, cropping if needed. The value is a number, but can be clearer to express as a fraction, e.g. `aspectRatio={16/9}`
321
322
-**placeholder**: Format of generated placeholder image.
322
-
-`BLURRED`: (default) a blurred, low resolution image, encoded as a base64 data URI
323
-
-`TRACED_SVG`: a low-resolution traced SVG of the image.
323
+
-`DOMINANT_COLOR`: (default) A solid color, calculated from the dominant color of the image.
324
+
-`BLURRED`: a blurred, low resolution image, encoded as a base64 data URI
325
+
-`TRACED_SVG`: a single-color traced SVG of the image.
324
326
-`NONE`: no placeholder. Set "background" to use a fixed background color.
325
-
-`DOMINANT_COLOR`: a solid color, calculated from the dominant color of the image.
326
327
-**layout**: The layout for the image.
327
328
-`CONSTRAINED`: (default) Resizes to fit its container, up to a maximum width, at which point it will remain fixed in size.
328
329
-`FIXED`: A static image size, that does not resize according to the screen width
329
330
-`FULL_WIDTH`: The image resizes to fit its container. Pass a "sizes" option if it isn't going to be the full width of the screen.
330
-
-**outputPixelDensities**: A list of image pixel densities to generate, for high-resolution (retina) screens. It will never generate images larger than the source, and will always include a 1x image.
331
-
Default is `[ 0.25, 0.5, 1, 2 ]`, for fullWidth/constrained images, and `[ 1, 2 ]` for fixed.
332
331
-**sizes**: The "[sizes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images)" attribute, passed to the `<img>` tag. This describes the display size of the image. This does not affect the generated images, but is used by the browser to decide which images to download. You can leave this blank for fixed images, or if the responsive image container will be the full width of the screen. In these cases we will generate an appropriate value. If, however, you are generating responsive images that are not the full width of the screen, you should provide a sizes property for best performance. You can alternatively pass this value to the component.
333
332
-**formats**: an array of file formats to generate. The default is `[AUTO, WEBP]`, which means it will generate images in the same format as the source image, as well as in the next-generation [WebP](https://developers.google.com/speed/webp) format. We strongly recommend you do not change this option, as doing so will affect performance scores.
334
333
-**quality**: The default quality. This is overridden by any format-specific options
335
-
-**blurredOptions**: Options for the low-resolution placeholder image. Set placeholder to "BLURRED" to use this
334
+
-**outputPixelDensities**: A list of image pixel densities to generate, for high-resolution (retina) screens. It will never generate images larger than the source, and will always include a 1x image.
335
+
Default is `[ 0.25, 0.5, 1, 2 ]`, for `CONSTRAINED` images, and `[ 1, 2 ]` for `FIXED`. Ignored for `FULL_WIDTH`, which uses `breakpoints` instead.
336
+
-**breakpoints**: Output widths to generate for full width images. Default is `[750, 1080, 1366, 1920]`, which is suitable for most common device resolutions. It will never generate an image larger than the source image. The browser will automatically choose the most appropriate.
337
+
-**blurredOptions**: Options for the low-resolution placeholder image. Set placeholder to `BLURRED` to use this
336
338
- width
337
339
- toFormat
338
-
-**tracedSVGOptions**: Options for traced placeholder SVGs. You also should set placeholder to "SVG".
340
+
-**tracedSVGOptions**: Options for traced placeholder SVGs. You also should set placeholder to `TRACED_SVG`.
339
341
-**jpgOptions**: Options to pass to sharp when generating JPG images.
@@ -103,16 +111,12 @@ export async function generateImageData({
103
111
reporter.warn(
104
112
`Specifying fullWidth images will ignore the width and height arguments, you may want a constrained image instead. Otherwise, use the breakpoints argument.`
105
113
)
106
-
args.width=undefined
114
+
args.width=metadata.width
107
115
args.height=undefined
108
116
}
109
117
110
118
if(!args.width&&!args.height&&metadata.width){
111
-
if(layout===`fullWidth`){
112
-
args.width=Math.round(metadata.width/2)
113
-
}else{
114
-
args.width=metadata.width
115
-
}
119
+
args.width=metadata.width
116
120
}
117
121
118
122
if(args.aspectRatio){
@@ -206,9 +210,10 @@ export async function generateImageData({
0 commit comments