diff --git a/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageSliderComparison3.tsx b/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageSliderComparison3.tsx index a69a31e2c5..e84b4f5d6a 100644 --- a/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageSliderComparison3.tsx +++ b/invokeai/frontend/web/src/features/gallery/components/ImageViewer/ImageSliderComparison3.tsx @@ -1,5 +1,6 @@ import { Box, Flex, Icon } from '@invoke-ai/ui-library'; import { useMeasure } from '@reactuses/core'; +import type { Dimensions } from 'features/canvas/store/canvasTypes'; import { memo, useCallback, useMemo, useRef } from 'react'; import { PiCaretLeftBold, PiCaretRightBold } from 'react-icons/pi'; import type { ImageDTO } from 'services/api/types'; @@ -55,24 +56,32 @@ export const ImageSliderComparison = memo(({ firstImage, secondImage }: Props) = [onMouseMove, onMouseUp, updateHandlePos] ); - const fittedSize = useMemo(() => { - let width = containerSize.width; - let height = containerSize.height; - const aspectRatio = firstImage.width / firstImage.height; - if (firstImage.width > firstImage.height) { - width = firstImage.width; - height = width / aspectRatio; + const fittedSize = useMemo(() => { + // Fit the first image to the container + const targetAspectRatio = containerSize.width / containerSize.height; + const imageAspectRatio = firstImage.width / firstImage.height; + + if (firstImage.width <= containerSize.width && firstImage.height <= containerSize.height) { + return { width: firstImage.width, height: firstImage.height }; + } + + let width: number; + let height: number; + + if (imageAspectRatio > targetAspectRatio) { + // Image is wider than container's aspect ratio + width = containerSize.width; + height = width / imageAspectRatio; } else { - height = firstImage.height; - width = height * aspectRatio; + // Image is taller than container's aspect ratio + height = containerSize.height; + width = height * imageAspectRatio; } return { width, height }; - }, [containerSize.height, containerSize.width, firstImage.height, firstImage.width]); - - console.log({ containerSize, fittedSize }); + }, [containerSize.height, containerSize.width, firstImage]); return ( - + - + @@ -151,7 +165,6 @@ export const ImageSliderComparison = memo(({ firstImage, secondImage }: Props) = left={0} onMouseDown={onMouseDown} userSelect="none" - bg="rgba(255,0,0,0.3)" />