Skip to content

Commit

Permalink
fixup! Fix parsing empty and zero width/height value
Browse files Browse the repository at this point in the history
  • Loading branch information
martijngastkemper committed Aug 2, 2023
1 parent b686413 commit dc469c6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions util/resizeImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ function resizeImage(

const resizeOptions = { fit: fit };

if (width) {
width = parseInt(width, 10);
if (width > 0) {
resizeOptions.width = width;
}
const parsedWidth = width ? parseInt(width, 10) : 0;
if (parsedWidth > 0) {
resizeOptions.width = parsedWidth;
}

if (height) {
height = parseInt(height, 10);
if (height > 0) {
resizeOptions.height = height;
}
const parsedHeight = height ? parseInt(height, 10) : 0;
if (parsedHeight > 0) {
resizeOptions.height = parsedHeight;
}

const sharp = SHARP(body).withMetadata().resize(resizeOptions);
Expand Down

0 comments on commit dc469c6

Please sign in to comment.