Skip to content

Commit

Permalink
add: now the "resizeByPercentage" allows the image size to increase
Browse files Browse the repository at this point in the history
  • Loading branch information
DPende committed May 3, 2024
1 parent 7dbbce1 commit 5ddadec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/editpix.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ EditPix.prototype.toSepia = async function (image) {
}

EditPix.prototype.resizeByPercentage = async function (image, percentage) {
if (percentage < 1 || percentage > 100)
throw new Error("The percentage value is incorrect: it must be between 1 and 100");
return this.imageManager.resizeByPercentage(image, percentage);
}

Expand Down
4 changes: 2 additions & 2 deletions src/image-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ ImageManager.prototype.getPixelArray = async function (image) {
}

ImageManager.prototype.resizeByPercentage = async function (image, percentage) {
const newWidth = image.naturalWidth * (percentage / 100);
const newHeight = image.naturalHeight * (percentage / 100);
const newWidth = image.naturalWidth + image.naturalWidth * (percentage / 100);
const newHeight = image.naturalHeight + image.naturalHeight * (percentage / 100);
this.canvas.width = newWidth;
this.canvas.height = newHeight;
this.context.drawImage(image, 0, 0, newWidth, newHeight);
Expand Down

0 comments on commit 5ddadec

Please sign in to comment.