# Image
The Image module is used to manipulate images.
# Crop
The crop method is used to crop an image. It takes the following parameters:
imageBytesthe image to crop in base64 formatxthe x-coordinate of the top-left corner of the crop areaythe y-coordinate of the top-left corner of the crop areawidththe width of the crop areaheightthe 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:
imageBytesthe image to crop in base64 formatxthe x-coordinate of the pixelythe 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:
imageBytesthe 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:
imageBytesthe image to crop in base64 formatfactorthe 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:
color1the first color objectcolor2the 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:
redthe red component of the colorgreenthe green component of the colorbluethe 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:
REDGREENBLUEWHITEBLACK
# Example
var imageModule = Module.load('Image', { version: 'vX.Y.Z' });
var color = imageModule.RED;
← Html KantPlugin →