Skip to main content

ImageProcessorMixin

Process images as soon as they are uploaded, or process them all together. Currently JPEG, PNG and WebP files are supported. They can be resized or their quality can be reduced. Since we use the sharp library, many more options could be added.

Usage

const { ControlledContainerMixin, ImageProcessorMixin } = require("@semapps/ldp");

module.exports = {
name: 'file',
mixins: [ImageProcessorMixin, ControlledContainerMixin], // In that order
settings: {
path: '/files',
acceptedTypes: ['semapps:File'],
imageProcessor: {
maxWidth: 1900,
maxHeight: 1000,
jpeg: {},
png: {},
webp: {}
}
}
}

Settings

All settings relative to this mixin should be set in a imageProcessor key.

PropertyTypeDefaultDescription
maxWidthInteger1900Reduce all images whose width is larger than this number
maxHeightInteger1000Reduce all images whose height is larger than this number
jpegObject{ quality: 85 }See sharp jpeg for available options
pngObject{ compressionLevel: 8 }See sharp png for available options
webpObject{ quality: 85 }See sharp webp for available options

Actions

processImage

Process the given image using the settings above.

Parameters
PropertyTypeDefaultDescription
resourceUriObjectrequiredURI of the resource (must be of type semapps:File)

processAllImages

Process all images in the container using the settings above.

Parameters
PropertyTypeDefaultDescription
webIdStringIn a POD provider config, this allows to define the POD to process