Skip to content

Commit 7d9b815

Browse files
feat(ui): revert to original image when crop discarded
1 parent 6a447dd commit 7d9b815

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

invokeai/frontend/web/src/features/editImageModal/lib/editor.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type CropBox = {
1818
* The callbacks supported by the editor.
1919
*/
2020
type EditorCallbacks = {
21-
onCropBoxChange: Set<(crop: CropBox) => void>;
21+
onCropBoxChange: Set<(crop: Readonly<CropBox>) => void>;
2222
onCropReset: Set<() => void>;
2323
onZoomChange: Set<(zoom: number) => void>;
2424
onImageLoad: Set<() => void>;
@@ -598,13 +598,7 @@ export class Editor {
598598
* Update the crop box state and re-render all related Konva objects.
599599
*/
600600
private updateCropBox = (cropBox: CropBox) => {
601-
const { x, y, width, height } = cropBox;
602-
this.cropBox = {
603-
x: Math.floor(x),
604-
y: Math.floor(y),
605-
width: Math.floor(width),
606-
height: Math.floor(height),
607-
};
601+
this.cropBox = cropBox;
608602
this.updateKonvaCropOverlay();
609603
this.updateKonvaCropInteractionRect();
610604
this.updateKonvaCropInteractionGuides();

invokeai/frontend/web/src/features/settingsAccordions/components/VideoSettingsAccordion/StartingFrameImage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@ export const StartingFrameImage = () => {
5656
// re-opens the editor they see the same crop
5757
const onApplyCrop = async () => {
5858
const box = editor.getCropBox();
59-
if (!box || objectEquals(box, startingFrameImage?.crop?.box)) {
59+
if (objectEquals(box, startingFrameImage?.crop?.box)) {
6060
// If the box hasn't changed, don't do anything
6161
return;
6262
}
63+
if (!box || objectEquals(box, { x: 0, y: 0, width: originalImageDTO.width, height: originalImageDTO.height })) {
64+
// There is a crop applied but it is the whole iamge - revert to original image
65+
dispatch(startingFrameImageChanged(imageDTOToCroppableImage(originalImageDTO)));
66+
return;
67+
}
6368
const blob = await editor.exportImage('blob');
6469
const file = new File([blob], 'image.png', { type: 'image/png' });
6570

0 commit comments

Comments
 (0)