-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve original filename in single-image Upscayl #966
Comments
Hey @Nero1024x! 👋 I'm here to help you with any bugs, questions, or contributions you have in mind. Let's squash those bugs together! Yes, you can have an option not to rename files and leave output names as is. This would require modifying the
const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
const mainWindow = getMainWindow();
if (!mainWindow) {
logit("No main window found");
return;
}
// GET VARIABLES
const tileSize = payload.tileSize;
const compression = payload.compression;
const scale = payload.scale;
const useCustomWidth = payload.useCustomWidth;
const customWidth = useCustomWidth ? payload.customWidth : "";
const model = payload.model as string;
const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs as ImageFormat;
const overwrite = payload.overwrite as boolean;
const imagePath = decodePath(payload.imagePath);
const keepOriginalName = payload.keepOriginalName as boolean; // New parameter
let inputDir = getDirectoryFromPath(imagePath);
let outputDir = decodePath(payload.outputPath);
const fileNameWithExt = getFilenameFromPath(imagePath);
const fileName = parse(fileNameWithExt).name;
const outFile = keepOriginalName
? outputDir + slash + fileNameWithExt
: outputDir +
slash +
fileName +
"_upscayl_" +
(useCustomWidth ? `${customWidth}px_` : `${scale}x_`) +
model +
"." +
saveImageAs;
const isDefaultModel = DEFAULT_MODELS.includes(model);
// Check if windows can write the new filename to the file system
if (outFile.length >= 255) {
logit("Filename too long for Windows.");
mainWindow.webContents.send(COMMAND.UPSCAYL_ERROR, "The filename exceeds the maximum path length allowed by Windows. Please shorten the filename or choose a different save location.");
}
// UPSCALE
if (fs.existsSync(outFile) && !overwrite) {
// If already upscayled, just output that file
logit("✅ Already upscayled at: ", outFile);
mainWindow.webContents.send(COMMAND.UPSCAYL_DONE, outFile);
} else {
logit(
"✅ Upscayl Variables: ",
JSON.stringify({
model,
gpuId,
saveImageAs,
inputDir,
fileNameWithExt,
outputDir,
outFile,
fileName,
scale,
compression,
customWidth,
useCustomWidth,
tileSize,
}),
);
const upscayl = spawnUpscayl(
getSingleImageArguments({
inputDir: decodeURIComponent(inputDir),
fileNameWithExt: decodeURIComponent(fileNameWithExt),
outFile,
modelsPath: isDefaultModel
? modelsPath
: savedCustomModelsPath ?? modelsPath,
model,
scale,
gpuId,
saveImageAs,
customWidth,
compression,
tileSize,
}),
logit,
);
setChildProcesses(upscayl);
setStopped(false);
let failed = false;
const onData = (data: string) => {
logit(data.toString());
mainWindow.setProgressBar(parseFloat(data.slice(0, data.length)) / 100);
data = data.toString();
mainWindow.webContents.send(COMMAND.UPSCAYL_PROGRESS, data.toString());
if (data.includes("Error")) {
upscayl.kill();
failed = true;
} else if (data.includes("Resizing")) {
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
}
};
const onError = (data) => {
if (!mainWindow) return;
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(COMMAND.UPSCAYL_ERROR, data.toString());
failed = true;
upscayl.kill();
return;
};
const onClose = async () => {
if (!failed && !stopped) {
logit("💯 Done upscaling");
// Free up memory
upscayl.kill();
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(COMMAND.UPSCAYL_DONE, outFile);
showNotification("Upscayl", "Image upscayled successfully!");
}
};
upscayl.process.stderr.on("data", onData);
upscayl.process.on("error", onError);
upscayl.process.on("close", onClose);
}
};
export default imageUpscayl;
Add the export type ImageUpscaylPayload = {
imagePath: string;
outputPath: string;
scale: string;
model: string;
gpuId: string;
saveImageAs: ImageFormat;
overwrite: boolean;
compression: string;
noImageProcessing: boolean;
customWidth: string;
useCustomWidth: boolean;
tileSize: number;
keepOriginalName: boolean; // New property
};
Update the settings UI to include a toggle for import { useState } from "react";
// Add this state to manage the keepOriginalName setting
const [keepOriginalName, setKeepOriginalName] = useState(
localStorage.getItem("keepOriginalName") === "true"
);
// Add this handler to update the setting
const handleKeepOriginalNameChange = () => {
const newValue = !keepOriginalName;
setKeepOriginalName(newValue);
localStorage.setItem("keepOriginalName", newValue.toString());
};
// Add this toggle in the return statement of the SettingsTab component
<OverwriteToggle />
<TurnOffNotificationsToggle />
{/* KEEP ORIGINAL NAME TOGGLE */}
<div className="flex items-center">
<label htmlFor="keepOriginalName" className="mr-2">
{t("SETTINGS.KEEP_ORIGINAL_NAME.TITLE")}
</label>
<input
type="checkbox"
id="keepOriginalName"
checked={keepOriginalName}
onChange={handleKeepOriginalNameChange}
/>
</div>
Add the new setting to the localization files, such as "SETTINGS": {
"TITLE": "SETTINGS",
...
"KEEP_ORIGINAL_NAME": {
"TITLE": "KEEP ORIGINAL NAME",
"DESCRIPTION": "If enabled, Upscayl will keep the original name of the image file."
},
...
} This will allow users to enable or disable the renaming of files through the settings UI [1][2][3][4]. |
Hi @Nero1024x |
@abhishek-gaonkar Yes. Option to keep the same name as input files, but when output is different folder than input folder |
Understood.. @NayamAmarshe shall I take this? |
We're already doing this for batch upscayl. The file names will have the same names. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still happening, please reply to indicate so. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still happening, please reply to indicate so. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still happening, please reply to indicate so. |
Checklist
Description
Can we have option not to rename files, but leave output names as is? And I have no knowledge of coding. Thank you
Related Problem(s)
No response
Alternatives
No response
The text was updated successfully, but these errors were encountered: