Image parameters in Content SDK apps
When using the NextImage component (imported from @content-sdk\next) or the Image component (imported from @content-sdk\react), you can apply image parameters. Some of these parameters affect visual aspects of the rendered image, such as sizing. Others provide more generic metadata, such as the language or version of the image.
These parameters either appear in the srcset attribute of the rendered HTML img element or are appended to the image's source URL as query string parameters.
Here is a list of parameters you can define as part of the imageParams object for both Image and NextImage components:
|
Key |
Description |
|---|---|
|
|
Width in pixels. |
|
|
Height in pixels. |
|
|
Maximum width in pixels. |
|
|
Maximum height in pixels. |
|
|
Language (defaults to context language). |
|
|
Version (defaults to the latest version). |
|
|
Database name (defaults to context database). |
|
|
Background color (defaults to black). |
|
|
Whether to allow the image to stretch or upscale beyond its original size ( |
|
|
Whether to ignore the image's aspect ratio when resizing it ( |
|
|
Scale by floating point number (for example, |
|
|
Whether to return a version of the image optimized for use as a thumbnail ( |
|
|
Whether to disable media caching for both retrieval and storage ( |
The Image component also supports the standard srcSet property, which accepts a subset of imageParams keys (namely w, h, mw, mh, iar, as, and sc).
NextImage supports all next/image properties except src, and it does not support srcSet.
Examples
The Image component
The following example demonstrates how to configure an Image component with the srcSet and sizes properties. This example renders a responsive image with server-side resizing, and the parameters provided appear as corresponding srcset and sizes attributes on the resulting HTML img element.
For example:
<Image
field={props.fields.sample2}
srcSet={[{ mw: 300 }, { mw: 100 }]}
sizes="(min-width: 960px) 300px, 100px"
className="img-fluid"
/>The NextImage component
This first example shows how to leverage server-side resizing by providing image size parameters to a NextImage component via the imageParams property. Specifying the size of the image like this means you also need to set the Next.js unoptimized property to true.
<NextImage
field={props.fields.image}
unoptimized={true}
imageParams={{ mw: 100, mh: 50 }}
height="50"
width="94"/>
This second example uses priority to specify that the image has high priority and must be preloaded rather than lazy-loaded, and the fill property to cause the image to fill the parent element instead of having a specific width or height.
<NextImage
field={props.fields.image}
sizes="(min-width: 960px) 300px, 100px"
fill={true}
priority={true}
/>