(static) (require("middlewares/imageProcessorMiddleware"))(imagesDirectory, cacheDirectory, styles, headers) → {function}
Defines an expressJS middleware to process images.
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.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
imagesDirectory |
String | The path of the directory containing the images to process |
||||||||||||
cacheDirectory |
String | The path of the directory containing already processed images (for cache purpose) |
||||||||||||
styles |
Array | The list of available styles to process images with for each style: Properties
|
||||||||||||
headers |
Object | The name / value list of headers to send with the image when responding to the client |
Throws:
-
If imagesdirectory or styles is empty
- Type
- TypeError
Returns:
The ExpressJS middleware
- Type
- function
Example
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
Methods
(inner) fetchStyle(id) → {Object}
Fetches a style by its id from the list of styles.
Parameters:
Name | Type | Description |
---|---|---|
id |
String | The id of the style to fetch |
Returns:
The style description object
- Type
- Object