From 099ebdbc370e543bb70a1841a6e9587ea5721711 Mon Sep 17 00:00:00 2001 From: Kent Keirsey <31807370+hipsterusername@users.noreply.github.com> Date: Mon, 7 Jul 2025 17:26:26 -0400 Subject: [PATCH] fix --- .../web/src/features/imageActions/actions.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/src/features/imageActions/actions.ts b/invokeai/frontend/web/src/features/imageActions/actions.ts index ac8319a3a0..31d88d444e 100644 --- a/invokeai/frontend/web/src/features/imageActions/actions.ts +++ b/invokeai/frontend/web/src/features/imageActions/actions.ts @@ -85,17 +85,34 @@ export const createNewCanvasEntityFromImage = async (arg: { }) => { const { type, imageDTO, dispatch, getState, withResize, overrides: _overrides } = arg; const state = getState(); - const { x, y, width, height } = selectBboxRect(state); + const { x, y } = selectBboxRect(state); let imageObject: CanvasImageState; + let resizeWidth: number; + let resizeHeight: number; - if (withResize && (width !== imageDTO.width || height !== imageDTO.height)) { + if (withResize) { + // Use the same resizing logic as newCanvasFromImage + const base = selectBboxModelBase(state); + const ratio = imageDTO.width / imageDTO.height; + const optimalDimension = getOptimalDimension(base); + const { width, height } = calculateNewSize(ratio, optimalDimension ** 2, base); + resizeWidth = width; + resizeHeight = height; + } else { + // Use current bbox dimensions + const { width, height } = selectBboxRect(state); + resizeWidth = width; + resizeHeight = height; + } + + if (withResize && (resizeWidth !== imageDTO.width || resizeHeight !== imageDTO.height)) { const resizedImageDTO = await uploadImage({ file: await imageDTOToFile(imageDTO), image_category: 'general', is_intermediate: true, silent: true, - resize_to: { width, height }, + resize_to: { width: resizeWidth, height: resizeHeight }, }); imageObject = imageDTOToImageObject(resizedImageDTO); } else {