Toggle menu

Image Utilities

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

NameTypeDescription
mediaidInteger, requiredAn iCM media item ID. The most suitable image component associated with this media item will be resized
widthInteger, optionalThe required width (in pixels) of the final image
heightInteger, optionalThe required height (in pixels) of the final image
minwidthInteger, optionalThe minimum acceptable width of the final image. The minwidth argument cannot be used at the same time that an absolute width is specified
maxwidthInteger, optionalThe maximum acceptable width of the final image. The maxwidth argument cannot be used at the same time that an absolute width is specified
minheightInteger, optionalThe minimum acceptable height of the final image. The minheight argument cannot be used at the same time that an absolute height is specified
maxheightInteger, optionalThe maximum acceptable height of the final image. The maxheight argument cannot be used at the same time that an absolute height is specified
componentliststring, optionalA 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

NameTypeDescription
mediaidInteger, optionalThe media item ID (as numbered in iCM) to decache
mediaidsString (comma separated media IDs), optionalA 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;

Last modified on November 20, 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon