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 // Quit the app once all windows are closed
app.on("window-all-closed", () => { app.on("window-all-closed", () => {
if (process.platform !== "darwin") { app.quit();
app.quit();
}
}); });
ipcMain.on(COMMAND.STOP, stop); ipcMain.on(COMMAND.STOP, stop);

View File

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

View File

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

View File

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

View File

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

View File

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