1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-27 17:00:52 +01:00

Fix sharp pixel limit and compression and macos quit

This commit is contained in:
Nayam Amarshe 2023-09-16 16:04:35 +05:30
parent 737ab925d4
commit b620c568b6
6 changed files with 37 additions and 37 deletions

View File

@ -46,9 +46,7 @@ app.on("ready", async () => {
// Quit the app once all windows are closed
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
app.quit();
});
ipcMain.on(COMMAND.STOP, stop);

View File

@ -98,19 +98,15 @@ const createMainWindow = () => {
setSaveOutputFolder(lastSaveOutputFolder);
}
});
// GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE
// GET IMAGE COMPRESSION (NUMBER) FROM LOCAL STORAGE
mainWindow.webContents
.executeJavaScript('localStorage.getItem("quality");', true)
.then((lastSavedQuality: string | null) => {
if (lastSavedQuality !== null) {
if (parseInt(lastSavedQuality) === 100) {
setCompression(99);
} else {
setCompression(parseInt(lastSavedQuality));
}
.executeJavaScript('localStorage.getItem("compression");', true)
.then((lastSavedCompression: string | null) => {
if (lastSavedCompression !== null) {
setCompression(parseInt(lastSavedCompression));
}
});
// GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE
// GET OVERWRITE (BOOLEAN) FROM LOCAL STORAGE
mainWindow.webContents
.executeJavaScript('localStorage.getItem("overwrite");', true)
.then((lastSavedOverwrite: string | null) => {

View File

@ -18,23 +18,29 @@ const convertAndScale = async (
throw new Error("Could not grab the original image!");
}
// Resize the image to the scale
const newImage = sharp(upscaledImagePath)
const newImage = sharp(upscaledImagePath, {
limitInputPixels: false,
})
.resize(
originalImage.width && originalImage.width * parseInt(scale),
originalImage.height && originalImage.height * parseInt(scale)
)
.withMetadata(); // Keep metadata
// Convert compression percentage (0-100) to compressionLevel (0-9)
const compressionLevel = Math.round((compression / 100) * 9);
// Change the output according to the saveImageAs
if (saveImageAs === "png") {
newImage.png({ quality: 100 - compression });
newImage.png({ compressionLevel });
} else if (saveImageAs === "jpg") {
console.log("Quality: ", compression);
newImage.jpeg({ quality: 100 - compression });
console.log("compression: ", compression);
newImage.jpeg({ quality: compression });
}
// Save the image
const buffer = await newImage.toBuffer();
try {
await sharp(buffer).toFile(processedImagePath);
await sharp(buffer, {
limitInputPixels: false,
}).toFile(processedImagePath);
} catch (error) {
logit("❌ Error converting to: ", saveImageAs, error);
onError(error);

View File

@ -1,12 +1,12 @@
type QualityInputProps = {
type CompressionInputProps = {
compression: number;
handleQualityChange: (arg: any) => void;
handleCompressionChange: (arg: any) => void;
};
export function QualityInput({
export function CompressionInput({
compression,
handleQualityChange,
}: QualityInputProps) {
handleCompressionChange,
}: CompressionInputProps) {
return (
<div className="flex flex-col gap-2">
<div className="flex gap-1 text-sm font-medium uppercase">
@ -22,7 +22,7 @@ export function QualityInput({
min={0}
max={100}
value={compression}
onChange={handleQualityChange}
onChange={handleCompressionChange}
/>
</div>
);

View File

@ -12,7 +12,7 @@ import { useAtom, useAtomValue } from "jotai";
import { customModelsPathAtom, scaleAtom } from "../../atoms/userSettingsAtom";
import { modelsListAtom } from "../../atoms/modelsListAtom";
import useLog from "../hooks/useLog";
import { QualityInput } from "./QualityInput";
import { CompressionInput } from "./CompressionInput";
import ToggleOverwrite from "./ToggleOverwrite";
import { UpscaylCloudModal } from "../UpscaylCloudModal";
import { ResetSettings } from "./ResetSettings";
@ -126,14 +126,14 @@ function SettingsTab({
);
}
if (!localStorage.getItem("quality")) {
logit("⚙️ Setting quality to 100%");
localStorage.setItem("quality", JSON.stringify(compression));
if (!localStorage.getItem("compression")) {
logit("⚙️ Setting compression to 100%");
localStorage.setItem("compression", JSON.stringify(compression));
} else {
const currentlySavedQuality = localStorage.getItem("quality");
logit("⚙️ Getting quality from localStorage", compression);
if (currentlySavedQuality) {
setCompression(JSON.parse(currentlySavedQuality));
const currentlySavedCompression = localStorage.getItem("compression");
logit("⚙️ Getting compression from localStorage", compression);
if (currentlySavedCompression) {
setCompression(JSON.parse(currentlySavedCompression));
}
}
}, []);
@ -144,9 +144,9 @@ function SettingsTab({
localStorage.setItem("saveImageAs", format);
};
const handleQualityChange = (e) => {
const handleCompressionChange = (e) => {
setCompression(e.target.value);
localStorage.setItem("quality", e.target.value);
localStorage.setItem("compression", e.target.value);
};
const handleGpuIdChange = (e) => {
@ -194,9 +194,9 @@ function SettingsTab({
{/* IMAGE SCALE */}
<ImageScaleSelect scale={scale} setScale={setScale} />
<QualityInput
<CompressionInput
compression={compression}
handleQualityChange={handleQualityChange}
handleCompressionChange={handleCompressionChange}
/>
<SaveOutputFolderToggle

View File

@ -19,7 +19,7 @@ module.exports = {
},
plugins: [require("daisyui"), require("tailwind-scrollbar")],
daisyui: {
darkTheme: 'upscayl',
darkTheme: "upscayl",
themes: [
{
upscayl: {