# Image
The Image
module is used to manipulate images.
# Crop
The crop
method is used to crop an image. It takes the following parameters:
imageBytes
the image to crop in base64 formatx
the x-coordinate of the top-left corner of the crop areay
the y-coordinate of the top-left corner of the crop areawidth
the width of the crop areaheight
the height of the crop area
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var croppedImage = imageModule.crop(imageBytes, 10, 10, 100, 100);
# GetColorAt
The getColorAt
method is used to get the color of a pixel at a given coordinate. It takes the following parameters:
imageBytes
the image to crop in base64 formatx
the x-coordinate of the pixely
the y-coordinate of the pixel
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var color = imageModule.getColorAt(imageBytes, 10, 10);
// color is an object with the following properties: red, green, blue
# GetDimensions
The getDimensions
method is used to get the dimensions of an image. It takes the following parameters:
imageBytes
the image to crop in base64 format
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var dimensions = imageModule.getDimensions(imageBytes);
var width = dimensions.width;
var height = dimensions.height;
# Scale
The scale
method is used to scale an image. It takes the following parameters:
imageBytes
the image to crop in base64 formatfactor
the factor by which to scale the image
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
// Double the size of the image
var scaledImage = imageModule.scale(imageBytes, 2);
# Color distance
The colorDistance
method is used to calculate the difference between two colors. It takes the following parameters:
color1
the first color objectcolor2
the second color object
The return value is a number in [0;1] where 0 means the colors are identical and 1 means the colors are as different as black and white.
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var color1 = imageModule.RED;
var color2 = imageModule.toColorObject(145, 10, 17);
var distance = imageModule.colorDistance(color1, color2);
# Creating a color object
The toColorObject
method is used to create a color object. It takes the following parameters:
red
the red component of the colorgreen
the green component of the colorblue
the blue component of the color
The return value is an object with the following numerical properties: red, green, blue.
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var color = imageModule.toColorObject(145, 10, 17);
# Predefined colors
The Image
module provides the following predefined colors for the sake of convenience:
RED
GREEN
BLUE
WHITE
BLACK
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var color = imageModule.RED;
← Html KantPlugin →