Restrict Wrap Around Mode to Selection

I agree that using file layers would make it easier. But I still think this idea is interesting. It might be a lot of work to implement properly in Krita itself, but I thought of a way to do something similar with a script instead.

I made a quickly-written script that toggles between resizing the image to the selection (keeping the content offcanvas) and resizing the image to the contents, while also toggling wraparound mode.

# A script to toggle the image size between the selection and the content,
# and toggle wraparound mode
from krita import *

def accumulateBounds(parentNode, sum):
    sum |= parentNode.bounds()
    for child in parentNode.children():
        accumulateBounds(child, sum)

doc = Krita.instance().activeDocument()
selection = doc.selection()
if selection:
    if selection.width() == doc.width() and selection.height() == doc.height():
        # same as selection: expand image to content
        sum = QRect(doc.xOffset(),doc.yOffset(),doc.width(),doc.height())
        for topLevelNode in doc.topLevelNodes():
            accumulateBounds(topLevelNode, sum)
        doc.resizeImage(sum.x(), sum.y(), sum.width(), sum.height())
        
    else:
        # resize image to selection (without removing content)
        doc.resizeImage(selection.x(), selection.y(), selection.width(), selection.height())

Krita.instance().action("wrap_around_mode").trigger()

It could be bound to a Ten Scripts shortcut.

6 Likes