fix: Always use bbox bounds for Controlnet Image (canvas)

This commit is contained in:
blessedcoolant 2023-09-27 04:03:14 +05:30 committed by psychedelicious
parent 50d254fdb7
commit acee4bd282
2 changed files with 16 additions and 12 deletions

View File

@ -3,9 +3,9 @@ import { canvasImageToControlNet } from 'features/canvas/store/actions';
import { getBaseLayerBlob } from 'features/canvas/util/getBaseLayerBlob'; import { getBaseLayerBlob } from 'features/canvas/util/getBaseLayerBlob';
import { controlNetImageChanged } from 'features/controlNet/store/controlNetSlice'; import { controlNetImageChanged } from 'features/controlNet/store/controlNetSlice';
import { addToast } from 'features/system/store/systemSlice'; import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next';
import { imagesApi } from 'services/api/endpoints/images'; import { imagesApi } from 'services/api/endpoints/images';
import { startAppListening } from '..'; import { startAppListening } from '..';
import { t } from 'i18next';
export const addCanvasImageToControlNetListener = () => { export const addCanvasImageToControlNetListener = () => {
startAppListening({ startAppListening({
@ -16,7 +16,7 @@ export const addCanvasImageToControlNetListener = () => {
let blob; let blob;
try { try {
blob = await getBaseLayerBlob(state); blob = await getBaseLayerBlob(state, true);
} catch (err) { } catch (err) {
log.error(String(err)); log.error(String(err));
dispatch( dispatch(

View File

@ -1,11 +1,14 @@
import { getCanvasBaseLayer } from './konvaInstanceProvider';
import { RootState } from 'app/store/store'; import { RootState } from 'app/store/store';
import { getCanvasBaseLayer } from './konvaInstanceProvider';
import { konvaNodeToBlob } from './konvaNodeToBlob'; import { konvaNodeToBlob } from './konvaNodeToBlob';
/** /**
* Get the canvas base layer blob, with or without bounding box according to `shouldCropToBoundingBoxOnSave` * Get the canvas base layer blob, with or without bounding box according to `shouldCropToBoundingBoxOnSave`
*/ */
export const getBaseLayerBlob = async (state: RootState) => { export const getBaseLayerBlob = async (
state: RootState,
alwaysUseBoundingBox: boolean = false
) => {
const canvasBaseLayer = getCanvasBaseLayer(); const canvasBaseLayer = getCanvasBaseLayer();
if (!canvasBaseLayer) { if (!canvasBaseLayer) {
@ -24,7 +27,8 @@ export const getBaseLayerBlob = async (state: RootState) => {
const absPos = clonedBaseLayer.getAbsolutePosition(); const absPos = clonedBaseLayer.getAbsolutePosition();
const boundingBox = shouldCropToBoundingBoxOnSave const boundingBox =
shouldCropToBoundingBoxOnSave || alwaysUseBoundingBox
? { ? {
x: boundingBoxCoordinates.x + absPos.x, x: boundingBoxCoordinates.x + absPos.x,
y: boundingBoxCoordinates.y + absPos.y, y: boundingBoxCoordinates.y + absPos.y,