I’ve been working on a quick demonstration of a mockup generator for Krita using 5.2. I can’t seem to get the TransformMask.scaleNode to actually scale the imported FileLayer. I’m hoping someone on here can point me in the right direction. I really like simplicity if possible.
The code is pasted below with a highlight on the line of code that doesn’t seem to be working at all…no errors, just doesn’t scale the transform mask.
from krita import *
import os
import time
def import_images_into_mockup(mockup_path, images_directory, output_directory):
application = Krita.instance()
currentDoc = application.activeDocument()
currentLayer = currentDoc.activeNode()
configParameters = InfoObject()
configParameters.setProperties({
'alpha': True,
'compression': 1,
'forceSRGB': True,
'indexed': True,
'interlaced': True,
'saveSRGBProfile': False,
'transparencyFillcolor': [255,255,255]
})
# Loop through image files in the directory designated from the prompt
for filename in os.listdir(images_directory):
if filename.endswith(".png") or filename.endswith(".jpg"):
image_path = os.path.join(images_directory, filename)
# Create a new layer with the imported image but allow the mockup to be on top with transparent section
scalingMethod = "none"
new_layer = currentDoc.createFileLayer(filename, image_path,scalingMethod)
root = currentDoc.rootNode()
root.addChildNode(new_layer,currentDoc.nodeByName("Root"))
# Create a transfrom mask to resize the image
mask = currentDoc.createNode('Transform', 'transformmask')
new_layer.addChildNode(mask, None)
transform_mask = currentDoc.nodeByName("Transform")
print(transform_mask.type())
# Set the position and size of the new layer to match the mockup layer
# ------------------PROBLEM LINE BELOW--------------------------
transform_mask.scaleNode(QPoint(207,126),593,419,"Bicubic")
# Export the mocked up image to the designated directory
output_name = output_directory + "/Mockup_" + filename
print(output_name)
currentDoc.exportImage(output_name,configParameters)
# Remove the image layer from the template to prepare for the next iteration
new_layer.remove()
def main():
# Ask the user for paths
mockup_path = "C://Users//lv2sr//Documents//Home//ART//Mockups//Mockup Room1.kra"
images_directory = QFileDialog.getExistingDirectory(None,"Select Image Directory", "*")
output_directory = QFileDialog.getExistingDirectory(None,"Select Export Directory", "*")
# Calls the function to import images into the mockup template
import_images_into_mockup(mockup_path, images_directory, output_directory)
if __name__ == "__main__":
main()