The Image Utilities worker provides methods for manipulating image files. Note, the worker depends on the icmapi worker. The URL for this service is given as an argument to the worker.
The Image Handling article looks at this worker, and how it is used by our sites, in more detail.
API
resizemediaitem
Pick the most suitably sized image component from an iCM media item, and then crop and scale it so that it fits the size constraint (and optionally image component) arguments. The original image files will be left in place, the resized version will be saved in a new directory in the iCM media directory.
Parameters
Name | Type | Description |
---|---|---|
mediaid | Integer, required | An iCM media item ID. The most suitable image component associated with this media item will be resized |
width | Integer, optional | The required width (in pixels) of the final image |
height | Integer, optional | The required height (in pixels) of the final image |
minwidth | Integer, optional | The minimum acceptable width of the final image. The minwidth argument cannot be used at the same time that an absolute width is specified |
maxwidth | Integer, optional | The maximum acceptable width of the final image. The maxwidth argument cannot be used at the same time that an absolute width is specified |
minheight | Integer, optional | The minimum acceptable height of the final image. The minheight argument cannot be used at the same time that an absolute height is specified |
maxheight | Integer, optional | The maximum acceptable height of the final image. The maxheight argument cannot be used at the same time that an absolute height is specified |
componentlist | string, optional | A comma separated list (case sensitive) of media item component names that will be considered when finding the most suitable image component to be used. A single component name will restrict the resize to that specific component only |
Returns
An object containing:
- mediapath - path to the final image within the iCM media directory
- abspath - absolute path to the final image
- height - height of the final image - not returned when the image was found in cache
- width - width of the final image - not returned when the image was found in cache
- src.mediapath - path (within the iCM media directory) to the source image which was resized - not returned when the image was found in cache
- src.abspath - path (absolute) to the source image which was resized - not returned when the image was found in cache
Example
let result = this.callWorkerMethod("imageutils", "resizemediaitem", {
"mediaid": 1,
"width": 30,
"height": 30
});
return result;
Returns
"result": {
"abspath": "<full path to site root>\\media\\generated\\1\\0x30@45.jpg",
"height": 30,
"mediapath": "generated\\1\\0x30@45.jpg",
"width": 45,
"src": {
"abspath": "<full path to site root>\\media\\image\\r\\j\\hot-air-1373167_1920.jpg",
"mediapath": "image\\r\\j\\hot-air-1373167_1920.jpg"
}
}
decachemediaitem
This method decaches one or more media items.
Once an image has been generated at a new size, it is saved as a new file in the media directory. Future requests for the size will use the previously resized image. This method deletes all the previously generated images.
Parameters
Name | Type | Description |
---|---|---|
mediaid | Integer, optional | The media item ID (as numbered in iCM) to decache |
mediaids | String (comma separated media IDs), optional | A list of media IDs to decache |
Returns
An object containing:
- cacheExisted - will be true if the cache existed
- successful - will be true if the cache was cleared
Example
let result = this.callWorkerMethod("imageutils", "decachemediaitem", {
"mediaid": 5312
});
return result;