I looked at the previous threads tagged scripting help and didn’t see anything similar. I’m on 5.1.5, but I don’t see anything in the 5.2 release notes that looks relevant to my issue.
I’ve been learning the script api recently, and one thing I would like to do is to scale an image after pasting it into a new document. The pasting part works until I try using Document.scaleImage()
from krita import *
doc_cur = Krita.instance().activeDocument()
a_node = doc_cur.activeNode()
img_w = doc_cur.width()
img_h = doc_cur.height()
doc_new = Application.createDocument(img_w,img_h, "Temp Tile Preview", "RGBA", "U8", "", 120.0)
pixels = a_node.pixelData(0,0,img_w,img_h)
root = doc_new.rootNode()
a_node = doc_new.createNode("layertopasteto","paintLayer")
a_node.setPixelData(pixels,0,0,img_w,img_h)
root.addChildNode(a_node,None)
view = Application.activeWindow().addView(doc_new)
new_w = int(img_w/8)
new_h = int(img_h/8)
doc_new.scaleImage(new_w,new_h,new_w,new_h,'Lanczos3')
When doc_new.scaleImage() is present the new document opens in krita and I can see the image for a frame (or similar low amount of time) before it disappears. Maybe I’m seeing it at the larger res before the scaling happens? If I remove the scaleImage() call it is visible, but obviously not scaled.
If I toggle the layers it’s still not visible.
If I save the image and reload it, the image will be visible and scaled to the correct size, but I would like to not have to do that.
I’ve tried a few things, Document.refreshProjection() looks relevant, but doesn’t fix this. I’ve tried resizing the image with Document.resizeImage() after the scale, and I’ve tried resizing with Document.setWidth() and Document.setHeight(), but none of them help.
Is there something I’m missing? I know I can simply use the GUI resize menu or use something like imagemagick, but the whole reason I want to do this is to automate my existing workflow of copying to a new document and resizing with image->scale image to new size