diffusionbee-stable-diffusion-ui icon indicating copy to clipboard operation
diffusionbee-stable-diffusion-ui copied to clipboard

Crop Outpainting saves to content

Open Leland opened this issue 2 years ago • 5 comments

Outpainting today saves the entire artboard – including image resize handles – even while mostly blank.

Here's a real export:

13d3

It means that users have to manually crop down saves to the content every time, or grab the raw images from the internal save directory.

It would be grand if DiffusionBee instead just cropped the height and width to the edges of the content.

Leland avatar Oct 30 '22 17:10 Leland

This is something I was thinking about too. Definitely would save time instead of having to manually scale afterwards.

EthanMcKanna avatar Oct 30 '22 21:10 EthanMcKanna

Thats a nice idea. If anyone could send a PR, that will be great

divamgupta avatar Oct 31 '22 01:10 divamgupta

Also if saving as a PNG, could it not also have alpha layer?

Polyculturerawks avatar Oct 31 '22 04:10 Polyculturerawks

Thinking about this issue – this is about fitting a minimum bounding rectangle around the drawn content, and then cropping to that box at save. The question is how we make the box.

Naive approach: track coordinates in state, update them when images are changed. Crop to the resulting box at save time.

Stateless approach: at save time, iterate over all Konva objects on the board to calculate bounding box. This will probably be a fair bit of code (and not very Vue-y).

But maybe there's a way to do this without iteration – maybe Konva can do this for us?

Other bits to think about:

  • Handling erasing (this is complex and enough of an edge (😉) case that it's probably not worth doing)
  • Handling undo (happens automatically with getClientRect)

Leland avatar Oct 31 '22 15:10 Leland

I guess iterating over Konva objects seem like the easiest and cleanest way to go about it.

divamgupta avatar Oct 31 '22 22:10 divamgupta