SharpAssetPreviewStrategy
This AssetPreviewStrategy uses the Sharp library to generate preview images of uploaded binary files. For non-image binaries, a generic "file" icon with the mime type overlay will be generated.
By default, this strategy will produce previews up to maximum dimensions of 1600 x 1600 pixels. The created preview images will match the input format - so a source file in jpeg format will output a jpeg preview, a webp source file will output a webp preview, and so on.
The settings for the outputs will default to Sharp's defaults (https://sharp.pixelplumbing.com/api-output). However, it is possible to pass your own configurations to control the output of each format:
- Implements:
AssetPreviewStrategy
constructor
(config?: SharpAssetPreviewConfig) => SharpAssetPreviewStrategygeneratePreviewImage
(ctx: RequestContext, mimeType: string, data: Buffer) => Promise<Buffer>This AssetPreviewStrategy uses the Sharp library to generate preview images of uploaded binary files. For non-image binaries, a generic "file" icon with the mime type overlay will be generated.
maxHeight
number1600The max height in pixels of a generated preview image.
maxWidth
number1600The max width in pixels of a generated preview image.
jpegOptions
sharp.JpegOptionsv1.7.0Set Sharp's options for encoding jpeg files: https://sharp.pixelplumbing.com/api-output#jpeg
pngOptions
sharp.PngOptionsv1.7.0Set Sharp's options for encoding png files: https://sharp.pixelplumbing.com/api-output#png
webpOptions
sharp.WebpOptionsv1.7.0Set Sharp's options for encoding webp files: https://sharp.pixelplumbing.com/api-output#webp
gifOptions
sharp.GifOptionsv1.7.0Set Sharp's options for encoding gif files: https://sharp.pixelplumbing.com/api-output#gif
avifOptions
sharp.AvifOptionsv1.7.0Set Sharp's options for encoding avif files: https://sharp.pixelplumbing.com/api-output#avif