Resize by percentage
Asynchronously resizes an image by a specified percentage.
This feature resizes the height and width of the image based on the percentage value you enter.
Syntax
resizeByPercentage(image, percentage)
Parameters
-
image :
HTMLImageElement
The image element to resize. -
percentage :
number
The percentage by which to resize the image. Positive values enlarge the image, while negative values shrink it.
Return
- Promise :
Promise<HTMLImageElement>
A promise that resolves with the resized image element.
Throws
Error
Thrown if there are errors during the resizing process.
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 = () => {
// resize image by percentage
editpix.resizeByPercentace(image, 40)
.then(resizedImage => {
// render modified image
document.body.appendChild(resizedImage)
})
.catch(error => { console.log(error) })
};