mirror of
https://github.com/upscayl/upscayl.git
synced 2025-01-19 01:24:09 +01:00
Add support for alpha channel in batch upscayl
This commit is contained in:
parent
3ed4638aa5
commit
f7803f7c9e
@ -84,6 +84,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
|
|
||||||
setStopped(false);
|
setStopped(false);
|
||||||
let failed = false;
|
let failed = false;
|
||||||
|
let isAlpha = false;
|
||||||
|
|
||||||
const onData = (data: any) => {
|
const onData = (data: any) => {
|
||||||
if (!mainWindow) return;
|
if (!mainWindow) return;
|
||||||
@ -97,6 +98,9 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
failed = true;
|
failed = true;
|
||||||
upscayl.kill();
|
upscayl.kill();
|
||||||
}
|
}
|
||||||
|
if (data.includes("has alpha channel")) {
|
||||||
|
isAlpha = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const onError = (data: any) => {
|
const onError = (data: any) => {
|
||||||
if (!mainWindow) return;
|
if (!mainWindow) return;
|
||||||
@ -138,9 +142,11 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
console.log("Filename: ", removeFileExtension(file));
|
console.log("Filename: ", removeFileExtension(file));
|
||||||
await convertAndScale(
|
await convertAndScale(
|
||||||
inputDir + slash + file,
|
inputDir + slash + file,
|
||||||
`${outputFolderPath}${slash}${removeFileExtension(
|
isAlpha
|
||||||
file
|
? `${outputFolderPath}${slash}${removeFileExtension(file)}.png`
|
||||||
)}.${saveImageAs}`,
|
: `${outputFolderPath}${slash}${removeFileExtension(
|
||||||
|
file
|
||||||
|
)}.${saveImageAs}`,
|
||||||
`${outputFolderPath}${slash}${removeFileExtension(
|
`${outputFolderPath}${slash}${removeFileExtension(
|
||||||
file
|
file
|
||||||
)}.${saveImageAs}`,
|
)}.${saveImageAs}`,
|
||||||
|
@ -26,6 +26,7 @@ import { DoubleUpscaylPayload } from "../../common/types/types";
|
|||||||
import { ImageFormat } from "../utils/types";
|
import { ImageFormat } from "../utils/types";
|
||||||
import getModelScale from "../../common/check-model-scale";
|
import getModelScale from "../../common/check-model-scale";
|
||||||
import showNotification from "../utils/show-notification";
|
import showNotification from "../utils/show-notification";
|
||||||
|
import { unlinkSync } from "fs";
|
||||||
|
|
||||||
const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
@ -162,16 +163,14 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
|||||||
mainWindow.setProgressBar(-1);
|
mainWindow.setProgressBar(-1);
|
||||||
mainWindow.webContents.send(
|
mainWindow.webContents.send(
|
||||||
COMMAND.DOUBLE_UPSCAYL_DONE,
|
COMMAND.DOUBLE_UPSCAYL_DONE,
|
||||||
isAlpha
|
outFile.replace(
|
||||||
? (outFile + ".png").replace(
|
/([^/\\]+)$/i,
|
||||||
/([^/\\]+)$/i,
|
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
|
||||||
encodeURIComponent((outFile + ".png").match(/[^/\\]+$/i)![0])
|
)
|
||||||
)
|
|
||||||
: outFile.replace(
|
|
||||||
/([^/\\]+)$/i,
|
|
||||||
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
if (isAlpha && saveImageAs === "jpg") {
|
||||||
|
unlinkSync(outFile + ".png");
|
||||||
|
}
|
||||||
showNotification("Upscayled", "Image upscayled successfully!");
|
showNotification("Upscayled", "Image upscayled successfully!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logit("❌ Error reading original image metadata", error);
|
logit("❌ Error reading original image metadata", error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user