Skip to main content

ImageTransformStrategy

ImageTransformStrategy

An injectable strategy which is used to determine the parameters for transforming an image. This can be used to implement custom image transformation logic, for example to limit transform parameters to a known set of presets.

This is set via the imageTransformStrategy option in the AssetServerOptions. Multiple strategies can be defined and will be executed in the order in which they are defined.

If a strategy throws an error, the image transformation will be aborted and the error will be logged, with an HTTP 400 response sent to the client.

Signature
interface ImageTransformStrategy extends InjectableStrategy {
getImageTransformParameters(
args: GetImageTransformParametersArgs,
): Promise<ImageTransformParameters> | ImageTransformParameters;
}

getImageTransformParameters

Given the input parameters, return the parameters which should be used to transform the image.

ImageTransformParameters

Parameters which are used to transform the image.

Signature
interface ImageTransformParameters {
width: number | undefined;
height: number | undefined;
mode: ImageTransformMode | undefined;
quality: number | undefined;
format: ImageTransformFormat | undefined;
fpx: number | undefined;
fpy: number | undefined;
preset: string | undefined;
}

width

property
number | undefined

height

property
number | undefined

mode

property
ImageTransformMode | undefined

quality

property
number | undefined

format

property
ImageTransformFormat | undefined

fpx

property
number | undefined

fpy

property
number | undefined

preset

property
string | undefined

GetImageTransformParametersArgs

The arguments passed to the getImageTransformParameters method of an ImageTransformStrategy.

Signature
interface GetImageTransformParametersArgs {
req: Request;
availablePresets: ImageTransformPreset[];
input: ImageTransformParameters;
}

req

property
Request

availablePresets

input