mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-28 01:10:52 +01:00
Fix compression
This commit is contained in:
parent
34db484936
commit
4d996dc380
@ -1,4 +1,4 @@
|
|||||||
import sharp from "sharp";
|
import sharp, { FormatEnum } from "sharp";
|
||||||
import logit from "./logit";
|
import logit from "./logit";
|
||||||
import { getMainWindow } from "../main-window";
|
import { getMainWindow } from "../main-window";
|
||||||
import { compression } from "./config-variables";
|
import { compression } from "./config-variables";
|
||||||
@ -28,21 +28,16 @@ const convertAndScale = async (
|
|||||||
|
|
||||||
// Convert compression percentage (0-100) to compressionLevel (0-9)
|
// Convert compression percentage (0-100) to compressionLevel (0-9)
|
||||||
const compressionLevel = Math.round((compression / 100) * 9);
|
const compressionLevel = Math.round((compression / 100) * 9);
|
||||||
if (saveImageAs === "png") {
|
logit("Compression: ", compression);
|
||||||
// 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",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const buffer = await newImage.toBuffer();
|
const buffer = await newImage.toBuffer();
|
||||||
try {
|
try {
|
||||||
await sharp(buffer, {
|
await sharp(buffer, {
|
||||||
limitInputPixels: false,
|
limitInputPixels: false,
|
||||||
|
})
|
||||||
|
.toFormat(saveImageAs as keyof FormatEnum, {
|
||||||
|
quality: 100 - (compression === 100 ? 99 : compression),
|
||||||
|
compressionLevel,
|
||||||
})
|
})
|
||||||
.withMetadata({
|
.withMetadata({
|
||||||
orientation: originalImage.orientation,
|
orientation: originalImage.orientation,
|
||||||
|
@ -15,6 +15,9 @@ export function CompressionInput({
|
|||||||
EXPERIMENTAL
|
EXPERIMENTAL
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<p className="text-xs text-base-content/80">
|
||||||
|
Please restart the app after changing this setting.
|
||||||
|
</p>
|
||||||
<input
|
<input
|
||||||
type="range"
|
type="range"
|
||||||
placeholder="Type here"
|
placeholder="Type here"
|
||||||
|
Loading…
Reference in New Issue
Block a user