1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-27 17:00:52 +01:00

Fix compression

This commit is contained in:
Nayam Amarshe 2023-09-17 05:44:41 +05:30
parent 34db484936
commit 4d996dc380
2 changed files with 9 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import sharp from "sharp";
import sharp, { FormatEnum } from "sharp";
import logit from "./logit";
import { getMainWindow } from "../main-window";
import { compression } from "./config-variables";
@ -28,22 +28,17 @@ const convertAndScale = async (
// Convert compression percentage (0-100) to compressionLevel (0-9)
const compressionLevel = Math.round((compression / 100) * 9);
if (saveImageAs === "png") {
// Change the output according to the saveImageAs
newImage.png({ compressionLevel });
} else if (saveImageAs === "jpg") {
console.log("compression: ", compression);
newImage.jpeg({
quality: 100 - (compression === 100 ? 99 : compression),
chromaSubsampling: "4:4:4",
});
}
logit("Compression: ", compression);
const buffer = await newImage.toBuffer();
try {
await sharp(buffer, {
limitInputPixels: false,
})
.toFormat(saveImageAs as keyof FormatEnum, {
quality: 100 - (compression === 100 ? 99 : compression),
compressionLevel,
})
.withMetadata({
orientation: originalImage.orientation,
density: originalImage.density,

View File

@ -15,6 +15,9 @@ export function CompressionInput({
EXPERIMENTAL
</p>
</div>
<p className="text-xs text-base-content/80">
Please restart the app after changing this setting.
</p>
<input
type="range"
placeholder="Type here"