Canvas Expander , resize canvas based on all paintlayers and active view

Canvas Expander

A krita extension that supplies helpful canvas related operations to help speed up workflow.

Features

  • Resize the document to fit all paint layers and viewport bounds, With options for just the layers or just the selected layer.

    Note that this does not trim the layers unlile ‘trim to selection’.
    The main utility of this function is to have something akin to mypaints infinite canvas.

  • Scale the document to zoom, dynamically re-scale the document based on current zoom making it now 100% zoom. Its ‘Scale Image To New size…’ without the menus!

    Note: this is a destructive operation

Useage & Shortcuts

Tools > Scripts > Canvas Expander ctrl+alt+shift+e
Tools > Scripts > Canvas Expander (Current Layer Only) ctrl+alt+shift+r
Tools > Scripts > Canvas Expander (layers Only) ctrl+alt+shift+t
Tools > Scripts > Canvas Expander (Scale to zoom) ctrl+alt+shift+s

Installation

Krita’s own guide

Current Release

  1. You probably want Document.resizeImage(x,y, w,h). It’s the same thing but all at once.
  2. Node.bounds() should match the contents of the layer, as far as I know.
  3. You can convert the widget size to zoomed image size like this:
zoom = view.canvas().zoomLevel()
scale = window.qwindow().devicePixelRatioF()
dpi = documement.resolution()

realZoom = zoom*scale / (dpi/72)

# width/height of the window, in zoomed image pixels
new_width = int(w_width * scale / realZoom)
new_height = int(w_height * scale / realZoom)
  • Also, if you want to use the viewport’s size instead of the window’s:
    viewport = window.qwindow().centralWidget()
  • One more thing, you can combine QRects like this: combined_bounds = combined_bounds.united(node.bounds())

thank you , now have working code just need to spend a little time rewriting into a functioning extension. :grinning:

Hello @TLTAA and welcome to the forum :slight_smile:

Would it be possible to also have a “Resize canvas to currently selected layer content” function?
I’d find that very useful if you could.

@AhabGreybeard I’ll add it to my notes :wink: just checking does this request differ from “image > trim to current layer”? It only just occurred to me that said operation “trims” the hidden parts of the other layers (which I’m guessing you’d like to avoid).

Trim resizes the canvas and also removes off-canvas content from around the specified region.
It’s a useful function but not what I need in some situations.
Hence my desire for ‘Resize to Current Layer’ but with no removal of any content from anywhere.

@AhabGreybeard ah thought that may be the case happy to oblige.

I’ve been asking for this for a long time. THANK YOU! :+1: :slight_smile:

@AhabGreybeard version 0.1.2 made with you’re request. :innocent:

Thank you @TLTAA :+1:
I’ll try this later in the day when I have time to concentrate on it and I’ll let you know if I have any difficulties with it.