Skip to content

Commit

Permalink
Merge pull request #55 from studio-YOLO/resize-by-percentage-enlarge-…
Browse files Browse the repository at this point in the history
…images

"resizeByPercentage" allows the image size to increase
  • Loading branch information
VinciGit00 authored May 4, 2024
2 parents bf94b72 + 5ddadec commit e87671a
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 e87671a

Please sign in to comment.