Module: imageProcessor

Defines functions to manipulate images.

Source:
Example
// Load module "imageProcessor"
var fsApi = require('@openveo/api').imageProcessor;

Methods

(static) aggregate(imagesPaths, destinationPath, width, height, horizontallyopt, qualityopt, temporaryDirectoryPathopt) → {module:imageProcessor~aggregateCallback}

Creates an image from a list of images.

Input images are aggregated horizontally or vertically to create the new image.

Parameters:
Name Type Attributes Default Description
imagesPaths Array

The list of paths of the images to add to the final image

destinationPath String

The final image path

width Number

The width of input images inside the image (in px)

height Number

The height of input images inside the image (in px)

horizontally Boolean <optional>
true

true to aggregate images horizontally, false to aggregate them vertically

quality Number <optional>
90

Expected quality from 0 to 100 (default to 90 with 100 the best)

temporaryDirectoryPath String <optional>

Path to the temporary directory to use to store intermediate images. It will be removed at the end of the operation. If not specified a directory is created in /tmp/

Source:
Returns:

callback Function to call when its done

Type
module:imageProcessor~aggregateCallback

(static) generateSprite(imagesPaths, destinationPath, width, height, totalColumnsopt, maxRowsopt, qualityopt, temporaryDirectoryPathopt) → {module:imageProcessor~generateSpriteCallback}

Generates a sprite from a list of images.

If the number of images exceeds the maximum number of images (depending on totalColumns and maxRows), extra images won't be in the sprite.

Parameters:
Name Type Attributes Default Description
imagesPaths Array

The list of images path to include in the sprite

destinationPath String

The sprite path

width Number

The width of images inside the sprite (in px)

height Number

The height of images inside the sprite (in px)

totalColumns Number <optional>
5

The number of images per line in the sprite

maxRows Number <optional>
5

The maximum number of lines of images in the sprite

quality Number <optional>
90

Expected quality from 0 to 100 (default to 90 with 100 the best)

temporaryDirectoryPath String <optional>

Path to the temporary directory to use to store intermediate images. It will be removed at the end of the operation. If not specified a directory is created in /tmp/

Source:
Returns:

callback Function to call when its done

Type
module:imageProcessor~generateSpriteCallback

(static) generateSpriteFreely(imagesPaths, destinationPath, qualityopt, temporaryDirectoryPathopt) → {module:imageProcessor~generateSpriteFreelyCallback}

Generates a sprite from a list of images without specifying images sizes nor grid size.

Size of images aren't changed. Images or simply packed by height with all images of the same height on the same line starting by images with higher height.

Parameters:
Name Type Attributes Default Description
imagesPaths Array

The list of images path to include in the sprite

destinationPath String

The sprite path

quality Number <optional>
90

Expected quality from 0 to 100 (default to 90 with 100 the best)

temporaryDirectoryPath String <optional>

Path to the temporary directory to use to store intermediate images. It will be removed at the end of the operation. If not specified a directory is created in /tmp/

Source:
Returns:

callback Function to call when its done

Type
module:imageProcessor~generateSpriteFreelyCallback

(static) generateSprites(imagesPaths, destinationPath, width, height, totalColumnsopt, maxRowsopt, qualityopt, temporaryDirectoryPathopt) → {module:imageProcessor~generateSpritesCallback}

Generates sprites from a list of images.

If the number of images don't fit in the grid defined by totalColumns * maxRows, then several sprites will be created. Additional sprites are suffixed by a number.

Parameters:
Name Type Attributes Default Description
imagesPaths Array

The list of images paths to include in the sprites

destinationPath String

The first sprite path, additional sprites are suffixed by a number

width Number

The width of images inside the sprite (in px)

height Number

The height of images inside the sprite (in px)

totalColumns Number <optional>
5

The number of images per line in the sprite

maxRows Number <optional>
5

The maximum number of lines of images in the sprite

quality Number <optional>
90

Expected quality from 0 to 100 (default to 90 with 100 the best)

temporaryDirectoryPath String <optional>

Path to the temporary directory to use to store intermediate images. It will be removed at the end of the operation. If not specified a directory is created in /tmp/

Source:
Returns:

callback Function to call when its done

Type
module:imageProcessor~generateSpritesCallback

(static) generateThumbnail(imagePath, thumbnailPath, widthopt, heightopt, cropopt, qualityopt, callback)

Generates a thumbnail from the given image.

Destination directory is automatically created if it does not exist.

Parameters:
Name Type Attributes Description
imagePath String

The image absolute path

thumbnailPath String

The thumbnail path

width Number <optional>

The expected image width (in px)

height Number <optional>

The expected image height (in px)

crop Boolean <optional>

Crop the image if the new ratio differs from original one

quality Number <optional>

Expected quality from 0 to 100 (default to 90 with 100 the best)

callback callback

Function to call when its done

Source:

Type Definitions

aggregateCallback(error, images)

Parameters:
Name Type Description
error Error | null

The error if an error occurred, null otherwise

images Array

The list of images

Properties
Name Type Description
sprite String

The path of the sprite file containing the image (destinationPath)

image String

The path of the original image

x Number

The x coordinate of the image top left corner inside the sprite

y Number

The y coordinate of the image top left corner inside the sprite

Source:

generateSpriteCallback(error, images)

Parameters:
Name Type Description
error Error | null

The error if an error occurred, null otherwise

images Array

The list of images

Properties
Name Type Description
sprite String

The path of the sprite file containing the image (destinationPath)

image String

The path of the original image

x Number

The x coordinate of the image top left corner inside the sprite

y Number

The y coordinate of the image top left corner inside the sprite

Source:

generateSpriteFreelyCallback(error, sprite)

Parameters:
Name Type Description
error Error | null

The error if an error occurred, null otherwise

sprite Object

The generated image

Properties
Name Type Description
path String

The path of the sprite file containing the images

images Array

The list of images inside the sprite

Properties
Name Type Description
path String

The path of the original image

x Number

The x coordinate of the image top left corner inside the sprite

y Number

The y coordinate of the image top left corner inside the sprite

size Object

The image size

Properties
Name Type Description
width Number

The image width

height Number

The image height

Source:

generateSpriteFreelyInternalCallback(error, sprite)

Parameters:
Name Type Description
error Error | null

The error if an error occurred, null otherwise

sprite Object

The generated image

Properties
Name Type Description
path String

The path of the sprite file containing the images

images Array

The list of images inside the sprite

Properties
Name Type Description
path String

The path of the original image

x Number

The x coordinate of the image top left corner inside the sprite

y Number

The y coordinate of the image top left corner inside the sprite

Source:

generateSpritesCallback(error, images)

Parameters:
Name Type Description
error Error | null

The error if an error occurred, null otherwise

images Array

The list of images

Properties
Name Type Description
sprite String

The path of the sprite file containing the image (destinationPath)

image String

The path of the original image

x Number

The x coordinate of the image top left corner inside the sprite

y Number

The y coordinate of the image top left corner inside the sprite

Source: