Skip to content

Commit e48bd14

Browse files
authored
fix: simplify resize percentage calculations (#388)
- simplify resize percentage calculations by removing redundant multiplications
1 parent 5f4cc2e commit e48bd14

File tree

1 file changed

+6
-4
lines changed
  • packages/wasm-image-processor/src

1 file changed

+6
-4
lines changed

packages/wasm-image-processor/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ function resize(image: photon.PhotonImage, width: number, height: number, usePer
1010
const imageWidth = image.get_width();
1111
const imageHeight = image.get_height();
1212

13-
const widthPercent = usePercent ? width : (width * 100.0) / imageWidth;
14-
const heightPercent = usePercent ? height : (height * 100.0) / imageHeight;
13+
const widthPercent = usePercent ? width : width / imageWidth;
14+
const heightPercent = usePercent ? height : height / imageHeight;
1515

16-
const newWidth = (imageWidth * widthPercent) / 100;
17-
const newHeight = (imageHeight * heightPercent) / 100;
16+
const newWidth = imageWidth * widthPercent;
17+
const newHeight = imageHeight * heightPercent;
1818

1919
return photon.resize(image, newWidth, newHeight, 1);
2020
}
@@ -45,6 +45,8 @@ function getImageResponse(image: photon.PhotonImage, format: SupportedImageForma
4545
break;
4646
}
4747

48+
// eslint-disable-next-line
49+
// @ts-ignore
4850
return new Response(finalImage, { headers: { 'Content-Type': contentType } });
4951
}
5052

0 commit comments

Comments
 (0)