SharpAssetPreviewStrategy
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:
AssetServerPlugin.init({
previewStrategy: new SharpAssetPreviewStrategy({
jpegOptions: { quality: 95 },
webpOptions: { quality: 95 },
}),
}),
Signature
class SharpAssetPreviewStrategy implements AssetPreviewStrategy {
constructor(config?: SharpAssetPreviewConfig)
async generatePreviewImage(ctx: RequestContext, mimeType: string, data: Buffer) => Promise<Buffer>;
}
Implements
Members
constructor
(config?: SharpAssetPreviewConfig) => SharpAssetPreviewStrategy
generatePreviewImage
(ctx: RequestContext, mimeType: string, data: Buffer) => Promise<Buffer>
SharpAssetPreviewConfig
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.
Signature
interface SharpAssetPreviewConfig {
maxHeight?: number;
maxWidth?: number;
jpegOptions?: sharp.JpegOptions;
pngOptions?: sharp.PngOptions;
webpOptions?: sharp.WebpOptions;
gifOptions?: sharp.GifOptions;
avifOptions?: sharp.AvifOptions;
}
Members
maxHeight
number
1600
maxWidth
number
1600
jpegOptions
sharp.JpegOptions
pngOptions
sharp.PngOptions
webpOptions
sharp.WebpOptions
gifOptions
sharp.GifOptions
avifOptions
sharp.AvifOptions