mirror of
https://github.com/upscayl/upscayl.git
synced 2025-02-12 09:03:00 +01:00
Fix #578
This commit is contained in:
parent
6ac1f8ce75
commit
c5d2f32d05
@ -28,13 +28,11 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
const model = payload.model;
|
const model = payload.model;
|
||||||
const gpuId = payload.gpuId;
|
const gpuId = payload.gpuId;
|
||||||
const saveImageAs = payload.saveImageAs;
|
const saveImageAs = payload.saveImageAs;
|
||||||
// const scale = payload.scale as string;
|
|
||||||
|
|
||||||
// GET THE IMAGE DIRECTORY
|
// GET THE IMAGE DIRECTORY
|
||||||
let inputDir = payload.batchFolderPath;
|
let inputDir = payload.batchFolderPath;
|
||||||
// GET THE OUTPUT DIRECTORY
|
// GET THE OUTPUT DIRECTORY
|
||||||
let outputDir = payload.outputPath;
|
let outputDir = payload.outputPath;
|
||||||
|
|
||||||
if (saveOutputFolder === true && outputFolderPath) {
|
if (saveOutputFolder === true && outputFolderPath) {
|
||||||
outputDir = outputFolderPath;
|
outputDir = outputFolderPath;
|
||||||
}
|
}
|
||||||
@ -44,27 +42,39 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
|
|
||||||
const isDefaultModel = DEFAULT_MODELS.includes(model);
|
const isDefaultModel = DEFAULT_MODELS.includes(model);
|
||||||
|
|
||||||
let scale = "4";
|
let initialScale = "4";
|
||||||
if (model.includes("x1")) {
|
if (model.includes("x1")) {
|
||||||
scale = "1";
|
initialScale = "1";
|
||||||
} else if (model.includes("x2")) {
|
} else if (model.includes("x2")) {
|
||||||
scale = "2";
|
initialScale = "2";
|
||||||
} else if (model.includes("x3")) {
|
} else if (model.includes("x3")) {
|
||||||
scale = "3";
|
initialScale = "3";
|
||||||
} else {
|
} else {
|
||||||
scale = "4";
|
initialScale = "4";
|
||||||
}
|
}
|
||||||
|
const desiredScale = payload.scale as string;
|
||||||
|
|
||||||
outputDir += slash + `upscayl_${model}_x${payload.scale}`;
|
const tempDirectory = outputDir + slash + "upscayl_temp";
|
||||||
|
outputDir +=
|
||||||
|
slash +
|
||||||
|
`upscayl_${model}_x${noImageProcessing ? initialScale : desiredScale}`;
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete .DS_Store files
|
// Create a folder in the output directory to store the original images
|
||||||
|
if (!fs.existsSync(tempDirectory)) {
|
||||||
|
fs.mkdirSync(tempDirectory, { recursive: true });
|
||||||
|
}
|
||||||
|
// Copy the files from the input directory to the output directory
|
||||||
fs.readdirSync(inputDir).forEach((file) => {
|
fs.readdirSync(inputDir).forEach((file) => {
|
||||||
if (file === ".DS_Store") {
|
if (
|
||||||
logit("🗑️ Deleting .DS_Store file");
|
file.toLocaleLowerCase().endsWith(".png") ||
|
||||||
fs.unlinkSync(inputDir + slash + file);
|
file.toLocaleLowerCase().endsWith(".jpg") ||
|
||||||
|
file.toLocaleLowerCase().endsWith(".jpeg") ||
|
||||||
|
file.toLocaleLowerCase().endsWith(".webp")
|
||||||
|
) {
|
||||||
|
fs.copyFileSync(inputDir + slash + file, tempDirectory + slash + file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,13 +82,13 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
const upscayl = spawnUpscayl(
|
const upscayl = spawnUpscayl(
|
||||||
"realesrgan",
|
"realesrgan",
|
||||||
getBatchArguments(
|
getBatchArguments(
|
||||||
inputDir,
|
tempDirectory,
|
||||||
outputDir,
|
outputDir,
|
||||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
||||||
model,
|
model,
|
||||||
gpuId,
|
gpuId,
|
||||||
"png",
|
"png",
|
||||||
scale
|
initialScale
|
||||||
),
|
),
|
||||||
logit
|
logit
|
||||||
);
|
);
|
||||||
@ -131,15 +141,15 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get number of files in output folder
|
// Get number of files in output folder
|
||||||
const files = fs.readdirSync(inputDir);
|
const files = fs.readdirSync(tempDirectory);
|
||||||
try {
|
try {
|
||||||
files.forEach(async (file) => {
|
files.forEach(async (file) => {
|
||||||
console.log("Filename: ", file.slice(0, -3));
|
console.log("Filename: ", file.slice(0, -3));
|
||||||
await convertAndScale(
|
await convertAndScale(
|
||||||
inputDir + slash + file,
|
tempDirectory + slash + file,
|
||||||
outputDir + slash + file.slice(0, -3) + "png",
|
outputDir + slash + file.slice(0, -3) + "png",
|
||||||
outputDir + slash + file.slice(0, -3) + saveImageAs,
|
outputDir + slash + file.slice(0, -3) + saveImageAs,
|
||||||
payload.scale,
|
desiredScale,
|
||||||
saveImageAs,
|
saveImageAs,
|
||||||
onError
|
onError
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user