mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-24 07:30:19 +01:00
Fix compression
This commit is contained in:
parent
b620c568b6
commit
1532dc24ef
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user