π Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.
TypeScript aielectronesrgangigapixelgigapixel-imagesimageimage-upscalingtopazupscaleupscalerimageupscayl
Fix double upscayl
Nayam Amarshe0cb8814615a8
diff --git a/electron/commands/double-upscayl.ts b/electron/commands/double-upscayl.tsindex 20e27bf..7dcb989 100644--- a/electron/commands/double-upscayl.ts+++ b/electron/commands/double-upscayl.ts@@ -20,6 +20,7 @@ import { modelsPath } from "../utils/get-resource-paths";import logit from "../utils/logit";import COMMAND from "../constants/commands";import sharp from "sharp";+import convertAndScale from "../utils/convert-and-scale";const doubleUpscayl = async (event, payload) => {const mainWindow = getMainWindow();@@ -42,8 +43,6 @@ const doubleUpscayl = async (event, payload) => {const fullfileName = imagePath.split(slash).slice(-1)[0] as string;const fileName = parse(fullfileName).name;- const outFile =- outputDir + slash + fileName + "_upscayl_16x_" + model + "." + saveImageAs;let scale = "4";if (model.includes("x2")) {@@ -54,6 +53,17 @@ const doubleUpscayl = async (event, payload) => {scale = "4";}+ const outFile =+ outputDir ++ slash ++ fileName ++ "_upscayl_" ++ parseInt(payload.scale) * parseInt(payload.scale) ++ "x_" ++ model ++ "." ++ saveImageAs;+// UPSCALElet upscayl = spawnUpscayl("realesrgan",@@ -117,41 +127,14 @@ const doubleUpscayl = async (event, payload) => {logit("β» Scaling and converting now...");mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);try {- const originalImage = await sharp(- inputDir + slash + fullfileName- ).metadata();- if (!mainWindow || !originalImage) {- throw new Error("Could not grab the original image!");- }- // Resize the image to the scale- const newImage = sharp(isAlpha ? outFile + ".png" : outFile)- .resize(- originalImage.width &&- originalImage.width * parseInt(payload.scale),- originalImage.height &&- originalImage.height * parseInt(payload.scale)- )- .withMetadata(); // Keep metadata- // Change the output according to the saveImageAs- if (saveImageAs === "png") {- newImage.png({ quality: 100 - quality });- } else if (saveImageAs === "jpg") {- newImage.jpeg({ quality: 100 - quality });- }- // Save the image- await newImage- .toFile(isAlpha ? outFile + ".png" : outFile)- .then(() => {- logit(- "β Done converting to: ",- isAlpha ? outFile + ".png" : outFile- );- })- .catch((error) => {- logit("β Error converting to: ", saveImageAs, error);- upscayl.kill();- onError(error);- });+ await convertAndScale(+ inputDir + slash + fullfileName,+ isAlpha ? outFile + ".png" : outFile,+ outFile,+ payload.scale,+ saveImageAs,+ onError+ );mainWindow.setProgressBar(-1);mainWindow.webContents.send(COMMAND.DOUBLE_UPSCAYL_DONE,diff --git a/electron/index.ts b/electron/index.tsindex ce0d738..c69b164 100644--- a/electron/index.ts+++ b/electron/index.ts@@ -17,9 +17,11 @@ import { execPath, modelsPath } from "./utils/get-resource-paths";import batchUpscayl from "./commands/batch-upscayl";import doubleUpscayl from "./commands/double-upscayl";import autoUpdate from "./commands/auto-update";+import sharp from "sharp";// INITIALIZATIONlog.initialize({ preload: true });+sharp.cache(false);logit("π App Path: ", app.getAppPath());app.whenReady().then(async () => {diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsxindex b14ff69..cd15611 100644--- a/renderer/pages/index.tsx+++ b/renderer/pages/index.tsx@@ -161,8 +161,8 @@ const Home = () => {// DOUBLE UPSCAYL DONEwindow.electron.on(COMMAND.DOUBLE_UPSCAYL_DONE, (_, data: string) => {setProgress("");+ setTimeout(() => setUpscaledImagePath(data), 500);setDoubleUpscaylCounter(0);- setUpscaledImagePath(data);logit(`π― DOUBLE_UPSCAYL_DONE: `, data);});@@ -595,7 +595,7 @@ const Home = () => {hideZoomOptions={true}/><img- src={`file:///${imagePath}`}+ src={"file:///" + imagePath}onLoad={(e: any) => {setDimensions({width: e.target.naturalWidth,