1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-09-24 03:18:28 +02:00
This commit is contained in:
Nayam Amarshe 2024-02-09 18:26:04 +05:30
parent 701b11875a
commit 54fc57f633
5 changed files with 27 additions and 13 deletions

View File

@ -145,20 +145,37 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
files.forEach(async (file) => { files.forEach(async (file) => {
if (file.startsWith(".") || file === outputFolderName) return; if (file.startsWith(".") || file === outputFolderName) return;
console.log("Filename: ", removeFileExtension(file)); console.log("Filename: ", removeFileExtension(file));
let upscaledImagePath = `${outputFolderPath}${slash}${removeFileExtension(
file,
)}.${saveImageAs}`;
if (
isAlpha &&
saveImageAs === "jpg" &&
fs.existsSync(
`${outputFolderPath}${slash}${removeFileExtension(file)}.jpg.png`,
)
) {
console.log("This is an Alpha image!");
upscaledImagePath = `${outputFolderPath}${slash}${removeFileExtension(file)}.jpg.png`;
}
await convertAndScale( await convertAndScale(
inputDir + slash + file, inputDir + slash + file,
isAlpha upscaledImagePath,
? `${outputFolderPath}${slash}${removeFileExtension(file)}.png`
: `${outputFolderPath}${slash}${removeFileExtension(
file,
)}.${saveImageAs}`,
`${outputFolderPath}${slash}${removeFileExtension( `${outputFolderPath}${slash}${removeFileExtension(
file, file,
)}.${saveImageAs}`, )}.${saveImageAs}`,
desiredScale, desiredScale,
saveImageAs, saveImageAs,
isAlpha,
); );
if (
isAlpha &&
saveImageAs === "jpg" &&
fs.existsSync(
`${outputFolderPath}${slash}${removeFileExtension(file)}.jpg.png`,
)
) {
fs.unlinkSync(upscaledImagePath);
}
}); });
mainWindow.webContents.send( mainWindow.webContents.send(
COMMAND.FOLDER_UPSCAYL_DONE, COMMAND.FOLDER_UPSCAYL_DONE,

View File

@ -161,7 +161,6 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
outFile, outFile,
desiredScale.toString(), desiredScale.toString(),
saveImageAs, saveImageAs,
isAlpha,
); );
mainWindow.setProgressBar(-1); mainWindow.setProgressBar(-1);
mainWindow.webContents.send( mainWindow.webContents.send(

View File

@ -176,7 +176,6 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
outFile, outFile,
desiredScale, desiredScale,
saveImageAs, saveImageAs,
isAlpha,
); );
// Remove the png file (default) if the saveImageAs is not png // Remove the png file (default) if the saveImageAs is not png
// fs.access( // fs.access(

View File

@ -10,9 +10,8 @@ const convertAndScale = async (
processedImagePath: string, processedImagePath: string,
scale: string, scale: string,
saveImageAs: ImageFormat, saveImageAs: ImageFormat,
isAlpha: boolean,
) => { ) => {
if (!isAlpha && !customWidth && scale === "4" && compression === 0) { if (!customWidth && scale === "4" && compression === 0) {
logit("Skipping compression for 4x scale and 0% compression"); logit("Skipping compression for 4x scale and 0% compression");
return; return;
} }
@ -36,7 +35,6 @@ const convertAndScale = async (
if (!originalImage) { if (!originalImage) {
throw new Error("Could not grab the original image!"); throw new Error("Could not grab the original image!");
} }
console.log("🚀 => originalImage:", originalImage);
// 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);
@ -71,8 +69,6 @@ const convertAndScale = async (
orientation: originalImage.orientation, orientation: originalImage.orientation,
}); });
console.log("🚀 => newImage:", newImage);
const buffer = await newImage const buffer = await newImage
.withMetadata({ .withMetadata({
density: originalImage.density, density: originalImage.density,

View File

@ -6,6 +6,9 @@ const logit = (...args: any) => {
const mainWindow = getMainWindow(); const mainWindow = getMainWindow();
if (!mainWindow) return; if (!mainWindow) return;
log.log(...args); log.log(...args);
if (process.env.NODE_ENV === "development") {
return;
}
mainWindow.webContents.send(COMMAND.LOG, args.join(" ")); mainWindow.webContents.send(COMMAND.LOG, args.join(" "));
}; };