Crop to content?

Is it possible to create a new layer from visible via scripting without actions 'cos I can’t get them working via kritarunner?

This is possible. You can make kra with images grouped into group layer. Then you can get pixelData/projectedPixelData of group without any actions involved. This pixels will be essentially “flattened” content of group with all stuff applied. Or you can get pixeldData of document rootNode, in that case groups not needed, this is literally ‘Visible’ result (after refreshProjection/waitForDone)
Did not try this via kritarunner though. But seems it should work

You can also directly feed this pixeldata to pillow and save png right away, without dialogs mangling and boring stuff. To load Pillow just call “sys.path.insert(0, … your local python installation site-packages path …)” before ( see Numpy/PIL/etc in Krita python - #3 by Ilja_Razinkov ) and then:

from PIL import Image
pixel_data = activeNode.projectionPixelData(…)
pil_img = Image.frombytes(“RGBA”, (ww, hh), pixel_data, “raw”, “BGRA”, 0, 1)
pil_img.save( … output path …)

This way you also do not have to crop anything, just get projectedPixelData of rectangle you need

1 Like