diff --git a/invokeai/frontend/web/src/features/controlNet/components/ControlNetImagePreview.tsx b/invokeai/frontend/web/src/features/controlNet/components/ControlNetImagePreview.tsx index 312d5a517b..6290d66052 100644 --- a/invokeai/frontend/web/src/features/controlNet/components/ControlNetImagePreview.tsx +++ b/invokeai/frontend/web/src/features/controlNet/components/ControlNetImagePreview.tsx @@ -5,12 +5,15 @@ import { stateSelector } from 'app/store/store'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions'; import IAIDndImage from 'common/components/IAIDndImage'; +import { setBoundingBoxDimensions } from 'features/canvas/store/canvasSlice'; import { TypesafeDraggableData, TypesafeDroppableData, } from 'features/dnd/types'; +import { setHeight, setWidth } from 'features/parameters/store/generationSlice'; +import { activeTabNameSelector } from 'features/ui/store/uiSelectors'; import { memo, useCallback, useMemo, useState } from 'react'; -import { FaSave, FaUndo } from 'react-icons/fa'; +import { FaRulerVertical, FaSave, FaUndo } from 'react-icons/fa'; import { useAddImageToBoardMutation, useChangeImageIsIntermediateMutation, @@ -54,6 +57,7 @@ const ControlNetImagePreview = ({ isSmall, controlNet }: Props) => { const dispatch = useAppDispatch(); const { pendingControlImages, autoAddBoardId } = useAppSelector(selector); + const activeTabName = useAppSelector(activeTabNameSelector); const [isMouseOverImage, setIsMouseOverImage] = useState(false); @@ -85,6 +89,24 @@ const ControlNetImagePreview = ({ isSmall, controlNet }: Props) => { addToBoard({ imageDTO: processedControlImage, board_id: autoAddBoardId }); }, [processedControlImage, autoAddBoardId, changeIsIntermediate, addToBoard]); + const handleSetControlImageToDimensions = useCallback(() => { + if (!processedControlImage) { + return; + } + + if (activeTabName === 'unifiedCanvas') { + dispatch( + setBoundingBoxDimensions({ + width: processedControlImage.width, + height: processedControlImage.height, + }) + ); + } else { + dispatch(setWidth(processedControlImage.width)); + dispatch(setHeight(processedControlImage.height)); + } + }, [processedControlImage, activeTabName, dispatch]); + const handleMouseEnter = useCallback(() => { setIsMouseOverImage(true); }, []); @@ -157,6 +179,12 @@ const ControlNetImagePreview = ({ isSmall, controlNet }: Props) => { tooltip="Save Control Image" styleOverrides={{ marginTop: 6 }} /> + : undefined} + tooltip="Set Control Image Dimensions To W/H" + styleOverrides={{ marginTop: 12 }} + /> @@ -192,6 +220,12 @@ const ControlNetImagePreview = ({ isSmall, controlNet }: Props) => { tooltip="Save Control Image" styleOverrides={{ marginTop: 6 }} /> + : undefined} + tooltip="Set Control Image Dimensions To W/H" + styleOverrides={{ marginTop: 12 }} + />