Skip to content

πŸ†™ Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.

Fix compression

Nayam Amarshe1532dc24efd7
diff --git a/electron/utils/convert-and-scale.ts b/electron/utils/convert-and-scale.ts
index dd933c9..15b4335 100644
--- a/electron/utils/convert-and-scale.ts
+++ b/electron/utils/convert-and-scale.ts
@@ -26,14 +26,17 @@ const convertAndScale = async (
originalImage.height && originalImage.height * parseInt(scale)
)
.withMetadata(); // Keep metadata
+
// Convert compression percentage (0-100) to compressionLevel (0-9)
const compressionLevel = Math.round((compression / 100) * 9);
- // Change the output according to the saveImageAs
if (saveImageAs === "png") {
+ // Change the output according to the saveImageAs
newImage.png({ compressionLevel });
} else if (saveImageAs === "jpg") {
console.log("compression: ", compression);
- newImage.jpeg({ quality: compression });
+ newImage.jpeg({
+ quality: 100 - (compression === 100 ? 99 : compression),
+ });
}
// Save the image
const buffer = await newImage.toBuffer();