Skip to main content

Saturation

This method asynchronously changes the saturation of the specified image element by applying a saturation adjustment factor.

Syntax

changeSaturation(image, factor)

Parameters

  • image : HTMLImageElement
    The image element to change the saturation of.

  • factor : number
    The saturation adjustment factor (-100 to 100):

    • factor > 0: the saturation gets increased by the factor.
    • factor < 0: the saturation gets decreased by the factor.
    • factor = 0: the image does not change.

Return

  • Promise : Promise<HTMLImageElement>
    A promise that resolves with the image element with adjusted saturation.

Throws

  • Error
    Thrown if the specified saturation factor is outside the valid range.

Examples

const editpix = new EditPix();

// image url
const url = "images/img.jpg";

// create image
var image = new Image();
image.src = url;

// waiting image load
image.onload = () => {
// change image saturation
editpix.changeSaturation(image, 20)
.then(resultImage => {
// render modified image
document.body.appendChild(resultImage);
})
.catch(error => { console.log(error) })
}