From 602cb72fdb88d98b0efb96183ba7830423fe8000 Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Sun, 21 Jan 2024 12:18:22 +0530 Subject: [PATCH] Add sidebar & Fix #644 --- electron/utils/convert-and-scale.ts | 38 +++++++++++++------ renderer/components/icons/SidebarClosed.tsx | 26 +++++++++++++ renderer/components/icons/SidebarOpened.tsx | 26 +++++++++++++ .../upscayl-tab/view/ImageOptions.tsx | 36 +++++++++++++----- renderer/public/sidebar.svg | 1 + 5 files changed, 106 insertions(+), 21 deletions(-) create mode 100644 renderer/components/icons/SidebarClosed.tsx create mode 100644 renderer/components/icons/SidebarOpened.tsx create mode 100644 renderer/public/sidebar.svg diff --git a/electron/utils/convert-and-scale.ts b/electron/utils/convert-and-scale.ts index b550116..f9f0292 100644 --- a/electron/utils/convert-and-scale.ts +++ b/electron/utils/convert-and-scale.ts @@ -36,18 +36,25 @@ const convertAndScale = async ( if (!originalImage) { throw new Error("Could not grab the original image!"); } + console.log("🚀 => originalImage:", originalImage); // Resize the image to the scale const newImage = sharp(upscaledImagePath, { limitInputPixels: false, - }).resize( - originalImage.width && originalImage.width * parseInt(scale), - originalImage.height && originalImage.height * parseInt(scale), - { - fit: "outside", - } - ); + }) + .resize( + originalImage.width && originalImage.width * parseInt(scale), + originalImage.height && originalImage.height * parseInt(scale), + { + fit: "outside", + } + ) + .withMetadata({ + density: originalImage.density, + orientation: originalImage.orientation, + }); + console.log("🚀 => newImage:", newImage); // Convert compression percentage (0-100) to compressionLevel (0-9) const compressionLevel = Math.round((compression / 100) * 9); @@ -63,11 +70,21 @@ const convertAndScale = async ( }) ); - const buffer = await newImage.toBuffer(); + const buffer = await newImage + .withMetadata({ + density: originalImage.density, + orientation: originalImage.orientation, + }) + .toBuffer(); + try { await sharp(buffer, { limitInputPixels: false, }) + .withMetadata({ + density: originalImage.density, + orientation: originalImage.orientation, + }) .toFormat(saveImageAs as keyof FormatEnum, { ...(saveImageAs === "jpg" && { quality: 100 - (compression === 100 ? 99 : compression), @@ -89,12 +106,9 @@ const convertAndScale = async ( lossless: compression === 0, smartSubsample: true, }), + force: true, }) - .withMetadata({ - orientation: originalImage.orientation, - density: originalImage.density, - }) .toFile(processedImagePath); } catch (error) { logit("❌ Error converting to: ", saveImageAs, error); diff --git a/renderer/components/icons/SidebarClosed.tsx b/renderer/components/icons/SidebarClosed.tsx new file mode 100644 index 0000000..f833dbd --- /dev/null +++ b/renderer/components/icons/SidebarClosed.tsx @@ -0,0 +1,26 @@ +import React from "react"; + +const SidebarClosed = ({ ...rest }) => { + return ( + + ); +}; + +export default SidebarClosed; diff --git a/renderer/components/icons/SidebarOpened.tsx b/renderer/components/icons/SidebarOpened.tsx new file mode 100644 index 0000000..156c5d3 --- /dev/null +++ b/renderer/components/icons/SidebarOpened.tsx @@ -0,0 +1,26 @@ +import React from "react"; + +const SidebarOpened = ({ ...rest }) => { + return ( + + ); +}; + +export default SidebarOpened; diff --git a/renderer/components/upscayl-tab/view/ImageOptions.tsx b/renderer/components/upscayl-tab/view/ImageOptions.tsx index 1a4c85c..c441e79 100644 --- a/renderer/components/upscayl-tab/view/ImageOptions.tsx +++ b/renderer/components/upscayl-tab/view/ImageOptions.tsx @@ -1,4 +1,6 @@ -import React, { useEffect } from "react"; +import SidebarClosed from "@/components/icons/SidebarClosed"; +import SidebarOpened from "@/components/icons/SidebarOpened"; +import React, { useEffect, useState } from "react"; const ImageOptions = ({ zoomAmount, @@ -11,6 +13,8 @@ const ImageOptions = ({ resetImagePaths: () => void; hideZoomOptions?: boolean; }) => { + const [openSidebar, setOpenSidebar] = useState(false); + useEffect(() => { if (!localStorage.getItem("zoomAmount")) { localStorage.setItem("zoomAmount", zoomAmount); @@ -20,15 +24,29 @@ const ImageOptions = ({ }, []); return ( -