mirror of
https://github.com/upscayl/upscayl.git
synced 2025-02-25 14:44:36 +01:00
Added zoom function
This commit is contained in:
parent
7fa8b1e95f
commit
5ddc5a8511
@ -3,9 +3,13 @@ import React from "react";
|
|||||||
const ImageOptions = ({
|
const ImageOptions = ({
|
||||||
zoomAmount,
|
zoomAmount,
|
||||||
setZoomAmount,
|
setZoomAmount,
|
||||||
|
leftImageRef,
|
||||||
|
rightImageRef,
|
||||||
}: {
|
}: {
|
||||||
zoomAmount: number;
|
zoomAmount: string;
|
||||||
setZoomAmount: (arg: any) => void;
|
setZoomAmount: (arg: any) => void;
|
||||||
|
leftImageRef: React.RefObject<HTMLImageElement>;
|
||||||
|
rightImageRef: React.RefObject<HTMLImageElement>;
|
||||||
}) => {
|
}) => {
|
||||||
const [zoomLevel, setZoomLevel] = React.useState("125");
|
const [zoomLevel, setZoomLevel] = React.useState("125");
|
||||||
|
|
||||||
@ -42,27 +46,40 @@ const ImageOptions = ({
|
|||||||
<div className="flex flex-row items-center gap-2">
|
<div className="flex flex-row items-center gap-2">
|
||||||
<p className="w-20">Zoom:</p>
|
<p className="w-20">Zoom:</p>
|
||||||
<button
|
<button
|
||||||
className="btn-primary btn"
|
className={`btn-primary btn ${
|
||||||
onClick={() => handleZoom(-1)}
|
zoomAmount === "100%" ? "btn-secondary" : "btn-primary"
|
||||||
disabled={zoomLevel === "100"}>
|
}`}
|
||||||
- 25%
|
onClick={() => setZoomAmount("100%")}>
|
||||||
</button>
|
|
||||||
<button className="btn-primary btn" onClick={() => handleZoom(0)}>
|
|
||||||
100%
|
100%
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="btn-primary btn"
|
className={`btn-primary btn ${
|
||||||
onClick={() => handleZoom(1)}
|
zoomAmount === "125%" ? "btn-secondary" : "btn-primary"
|
||||||
disabled={zoomLevel === "200"}>
|
}`}
|
||||||
+ 25%
|
onClick={() => setZoomAmount("125%")}>
|
||||||
|
125%
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`btn-primary btn ${
|
||||||
|
zoomAmount === "150%" ? "btn-secondary" : "btn-primary"
|
||||||
|
}`}
|
||||||
|
onClick={() => setZoomAmount("150%")}>
|
||||||
|
150%
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`btn-primary btn ${
|
||||||
|
zoomAmount === "175%" ? "btn-secondary" : "btn-primary"
|
||||||
|
}`}
|
||||||
|
onClick={() => setZoomAmount("175%")}>
|
||||||
|
175%
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`btn-primary btn ${
|
||||||
|
zoomAmount === "200%" ? "btn-secondary" : "btn-primary"
|
||||||
|
}`}
|
||||||
|
onClick={() => setZoomAmount("200%")}>
|
||||||
|
200%
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div className="flex flex-row items-center gap-2">
|
|
||||||
<p className="w-20">Position:</p>
|
|
||||||
<button className="btn-primary btn">Top</button>
|
|
||||||
<button className="btn-primary btn">Bottom</button>
|
|
||||||
<button className="btn-primary btn">Right</button>
|
|
||||||
<button className="btn-primary btn">Left</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,6 +13,7 @@ import RightPaneInfo from "../components/RightPaneInfo";
|
|||||||
import ImageOptions from "../components/ImageOptions";
|
import ImageOptions from "../components/ImageOptions";
|
||||||
import LeftPaneVideoSteps from "../components/LeftPaneVideoSteps";
|
import LeftPaneVideoSteps from "../components/LeftPaneVideoSteps";
|
||||||
import LeftPaneImageSteps from "../components/LeftPaneImageSteps";
|
import LeftPaneImageSteps from "../components/LeftPaneImageSteps";
|
||||||
|
import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
// STATES
|
// STATES
|
||||||
@ -34,7 +35,12 @@ const Home = () => {
|
|||||||
const [doubleUpscaylCounter, setDoubleUpscaylCounter] = useState(0);
|
const [doubleUpscaylCounter, setDoubleUpscaylCounter] = useState(0);
|
||||||
const [gpuId, setGpuId] = useState("");
|
const [gpuId, setGpuId] = useState("");
|
||||||
const [saveImageAs, setSaveImageAs] = useState("png");
|
const [saveImageAs, setSaveImageAs] = useState("png");
|
||||||
const [zoomAmount, setZoomAmount] = useState("");
|
const [zoomAmount, setZoomAmount] = useState("200%");
|
||||||
|
const [backgroundPosition, setBackgroundPosition] = useState("0% 0%");
|
||||||
|
|
||||||
|
// REFS
|
||||||
|
const leftImageRef = useRef();
|
||||||
|
const rightImageRef = useRef();
|
||||||
|
|
||||||
// EFFECTS
|
// EFFECTS
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -185,6 +191,13 @@ const Home = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// HANDLERS
|
// HANDLERS
|
||||||
|
const handleMouseMove = (e) => {
|
||||||
|
const { left, top, width, height } = e.target.getBoundingClientRect();
|
||||||
|
const x = ((e.pageX - left) / width) * 100;
|
||||||
|
const y = ((e.pageY - top) / height) * 100;
|
||||||
|
setBackgroundPosition(`${x}% ${y}%`);
|
||||||
|
};
|
||||||
|
|
||||||
const selectVideoHandler = async () => {
|
const selectVideoHandler = async () => {
|
||||||
resetImagePaths();
|
resetImagePaths();
|
||||||
|
|
||||||
@ -521,6 +534,8 @@ const Home = () => {
|
|||||||
<ImageOptions
|
<ImageOptions
|
||||||
zoomAmount={zoomAmount}
|
zoomAmount={zoomAmount}
|
||||||
setZoomAmount={setZoomAmount}
|
setZoomAmount={setZoomAmount}
|
||||||
|
leftImageRef={leftImageRef}
|
||||||
|
rightImageRef={rightImageRef}
|
||||||
/>
|
/>
|
||||||
<ReactCompareSlider
|
<ReactCompareSlider
|
||||||
itemOne={
|
itemOne={
|
||||||
@ -528,13 +543,18 @@ const Home = () => {
|
|||||||
<p className="absolute bottom-1 left-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
|
<p className="absolute bottom-1 left-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
|
||||||
Original
|
Original
|
||||||
</p>
|
</p>
|
||||||
<ReactCompareSliderImage
|
|
||||||
|
<img
|
||||||
src={"file://" + imagePath}
|
src={"file://" + imagePath}
|
||||||
alt="Original"
|
alt="Original"
|
||||||
style={{
|
style={{
|
||||||
objectFit: "contain",
|
objectFit: "contain",
|
||||||
|
backgroundPosition: "0% 10%",
|
||||||
|
transformOrigin: backgroundPosition,
|
||||||
}}
|
}}
|
||||||
className={`bg-[#1d1c23] ${zoomAmount}`}
|
onMouseMove={handleMouseMove}
|
||||||
|
ref={leftImageRef}
|
||||||
|
className={`h-full w-full bg-[#1d1c23] transition-transform group-hover:scale-[${zoomAmount}]`}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
@ -543,17 +563,21 @@ const Home = () => {
|
|||||||
<p className="absolute bottom-1 right-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
|
<p className="absolute bottom-1 right-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
|
||||||
Upscayled
|
Upscayled
|
||||||
</p>
|
</p>
|
||||||
<ReactCompareSliderImage
|
<img
|
||||||
src={"file://" + upscaledImagePath}
|
src={"file://" + upscaledImagePath}
|
||||||
alt="Upscayl"
|
alt="Upscayl"
|
||||||
style={{
|
style={{
|
||||||
objectFit: "contain",
|
objectFit: "contain",
|
||||||
|
backgroundPosition: "0% 10%",
|
||||||
|
transformOrigin: backgroundPosition,
|
||||||
}}
|
}}
|
||||||
className="bg-[#1d1c23]"
|
onMouseMove={handleMouseMove}
|
||||||
|
ref={rightImageRef}
|
||||||
|
className={`h-full w-full bg-[#1d1c23] transition-transform group-hover:scale-[${zoomAmount}]`}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
className="h-screen"
|
className="group h-screen"
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -4,9 +4,11 @@ module.exports = {
|
|||||||
"./renderer/components/**/*.{js,ts,jsx,tsx}",
|
"./renderer/components/**/*.{js,ts,jsx,tsx}",
|
||||||
],
|
],
|
||||||
safelist: [
|
safelist: [
|
||||||
{
|
"group-hover:scale-[100%]",
|
||||||
pattern: /scale-/,
|
"group-hover:scale-[125%]",
|
||||||
},
|
"group-hover:scale-[150%]",
|
||||||
|
"group-hover:scale-[175%]",
|
||||||
|
"group-hover:scale-[200%]",
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user