This is a great feature I miss from GIMP where it's called "Fit Canvas to Layers". It must be very easy to implement and it's good when creating collages or strips from multiple images. This function should set the canvas size so that all layers fit into it without margins. The algorithm is simple, iterate over the layers and find the "most left", "most top" etc. coordinate among them, then set it as the respective canvas coordinate. The excessive border would be cropped and any offscreen parts would be revealed. For now after putting the images next to each other I have to resize the canvas to some "big enough" size so that they all fit and then crop it down manually which is time consuming and boring.
Please mark feature requests as "wish". We already have resize canvas to layer size, but that only checks the current layer. You could easily implement this in Python in Krita 4.
(In reply to rkfg from comment #0) > This is a great feature I miss from GIMP where it's called "Fit Canvas to > Layers". It must be very easy to implement and it's good when creating > collages or strips from multiple images. This function should set the canvas > size so that all layers fit into it without margins. The algorithm is > simple, iterate over the layers and find the "most left", "most top" etc. > coordinate among them, then set it as the respective canvas coordinate. The > excessive border would be cropped and any offscreen parts would be revealed. > For now after putting the images next to each other I have to resize the > canvas to some "big enough" size so that they all fit and then crop it down > manually which is time consuming and boring. rkfg, I found a feature in Krita that may be what you are looking for. Select the layer(s) that you want to have the cropping performed around, and go to: Image --> Trim to current layer. You can also perform the same command for your current selection. Alternatively, it seems you can also apply the command to the entire image, which will remove any wasted empty space. Are any of these what you are looking for?
Setting to needinfo
Sorry for not answering sooner. No, this is not what I want because it just trims the image to the curent layer as the name suggests. The main problem is to make the image bigger when a layer is offscreen, not to cut it down. An example: take two images, put them on two distinct layers and then shift the top layer down so that half of it beyond the image's lower border. Now, how do we make the image big enough to see both images? To be precise, to see the top layer in full and half of the bottom one. Except, of course, doing it manually by resizing the canvas to some deliberately bigger size and then cropping it so that all of it fits.
Dear Bug Submitter, This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information as soon as possible and set the bug status as REPORTED. Due to regular bug tracker maintenance, if the bug is still in NEEDSINFO status with no change in 30 days, the bug will be closed as RESOLVED > WORKSFORME due to lack of needed information. For more information about our bug triaging procedures please read the wiki located here: https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging If you have already provided the requested information, please set the bug status as REPORTED so that the KDE team knows that the bug is ready to be confirmed. Thank you for helping us make KDE software even better for everyone!
Information provided.
You could also use the Grow mode of the crop tool for this. In theory, a simple python script like from krita import * d = Krita.instance().activeDocument() w = d.width() h = d.height() x = d.xOffset() y = d.yOffset() print(x, y, w, h) for n in d.topLevelNodes(): print (n, n.bounds()) b = n.bounds() if b.x() < x: x = b.x() if b.y() < y: y = b.y() if b.x() + b.width() > w: w = b.x() + b.width() if b.y() + b.height() > h: h = b.y() + b.height() print (x, y, w, h) d.setXOffset(x) d.setYOffset(y) d.setWidth(w) d.setHeight(h) Should do the trick, but setting the image dimensions seems to be broken. Which makes this a bug...
Ah, I don't know my own API. This script will do what you need (unless you have nested layers, then it needs to be rewritten a little): from krita import * d = Krita.instance().activeDocument() w = d.width() h = d.height() x = d.xOffset() y = d.yOffset() print(x, y, w, h) r = QRect(x, y, w, h) print(r) for n in d.topLevelNodes(): print (n, n.bounds()) b = n.bounds() r = r.united(b) print (r) d.resizeImage(r.x(), r.y(), r.width(), r.height())
Thank you, it works. But I'd much prefer it to be available as a menu item, as I'm not so familiar with scripting. I used "Scripter" to test this one but it's quite inconvenient to load the script each time.
Created attachment 115291 [details] A plugin that adds the script to the menu as well. Unpack this in .local/share (Linux) or in %APPDATA% and the script will be in the menu :-).
Hmm, this looks really great but I don't see this menu item in the "Image" menu. I'm on version 4.1.3, could it be that this python plugin support is not implemented in it?
To make it clear: I enabled the plugin in the settings, I can see its description but I don't see it in the menu.
It's in tools/scripts. Placing menu entries somewhere else is something I'm working on.
Oh, I see. <Menu name="Image"> confused me. Now it's all green, thanks for your work!