imageProcessorMiddleware
Summary
Defines an expressJS middleware to process images.
var openVeoApi = require('@openveo/api');
expressApp.use('/mount-path', openVeoApi.middlewares.imageProcessorMiddleware(
'/path/to/the/folder/containing/images'
'/path/to/the/folder/containing/processed/images/cache'
[
{
id: 'my-thumb', // Id of the style to apply when requesting an image processing
width: 200, // Expected width (in px) of the image
quality: 50 // Expected quality from 0 to 100 (default to 90 with 100 the best)
}
]
));
// Then it's possible to apply style "my-thumb" to the image /mount-path/my-image.jpg using
// parameter "style": /mount-path/my-image.jpg?style=my-thumb
If path corresponds to an image with a parameter "style", the style is applied to the image before returning it to the client. Actually only one type of manipulation can be applied to an image: generate a thumbnail. If path does not correspond to an image the processor is skipped.
Constructor
imageProcessorMiddleware
Syntax
Summary
Parameters:
-
imagesDirectory
StringThe path of the directory containing the images to process
-
cacheDirectory
StringThe path of the directory containing already processed images (for cache purpose)
-
styles
ArrayThe list of available styles to process images with for each style:
- [String] id Id of the style to apply when requesting an image processing
- [Number] [width] Expected width of the image (in px) (default to 10)
- [Number] [quality] Expected quality from 0 to 100 (default to 90 with 100 the best)
-
headers
ObjectThe name / value list of headers to send with the image when responding to the client
Returns:
Function:
The ExpressJS middleware