Skip to content
  • Creating a filter layer.

        # first, create a filter.
        desaturateFilter = Application.filter("desaturate")
        # get the config, and modify it. You can get the parameters from the 'xml' button in the filterdialog.
        config = desaturateFilter.configuration()
        config.setProperty("type", 2)
        desaturateFilter.setConfiguration(config)
        #Setup a selection, you need this for the filter layer.
        selection = Selection()
        selection.selectAll(exportNode, 255)
        # input everything into the filterLayer function.
        filterLayer = exportDoc.createFilterLayer("desaturateLayerName", desaturateFilter, selection)
        # add layer to document
        exportDoc.rootNode().addChildNode(filterLayer, exportNode)
  • Thank you Wolthera! I made a few customizations to tailor it to specific needs:

    • Only copy paintLayers because I didn't know how to programatically create the right filter you show me just above. So I decided to create a filterLayer at the top of my Storyboard file and copy it once each loop but not as a single file.
    • No save dialog but directly saving in ../kra)
    • Resize the exported image to fixed width
    • Changed the call to setChildNodes to addChildNode (the setChildNodes call would erase the Background layer which I need)
    • index with 1 padded 0
    • set the active layer in the new file (line 42). But it doesn't work for now. Any idea ?
    • Now this might be dirty but I used a lot of global variables to be able to set them all in one place and customize the script easily

    Here my take on it export_layers_to_seperate_kra_files.py

  • Here is my way to add a solid white background on an existing file.

    from krita import *
    import glob, os
    chapterPath = "Path to your base folder"
    os.chdir(chapterPath + "Path to your png folder")
    for f in glob.glob("*png"):
        # retrieve the document and create a view
        doc = Application.openDocument(os.path.realpath(f))
        window = Application.activeWindow()
        view = window.addView(doc)
        window.showView(view)
    
        # create a paint layer and put it at the bottom
        paintLayer = doc.createNode("Background", "paintLayer")
        root = doc.rootNode()
        children = root.childNodes()
        root.setChildNodes([paintLayer, children[0]])
        # fill the layer with white
        data = ([255] * doc.width() * doc.height())
        paintLayer.setPixelData(bytearray(data), 0, 0, doc.width(), doc.height())
    
        # Add a desaturation filter
        # first, create a filter.
        desaturateFilter = Application.filter("desaturate")
        # get the config, and modify it. You can get the parameters from the 'xml' button in the filterdialog.
        config = desaturateFilter.configuration()
        config.setProperty("type", 2)
        desaturateFilter.setConfiguration(config)
        #Setup a selection, you need this for the filter layer.
        selection = Selection()
        selection.selectAll(children[0], 255)
        # input everything into the filterLayer function.
        filterLayer = doc.createFilterLayer("desaturateLayerName", desaturateFilter, selection)
        filterLayer.setVisible(False)
        # add layer to document
        doc.rootNode().addChildNode(filterLayer)
    
        # save and close the document
        doc.saveAs("Path to your kra destination")
        doc.waitForDone()
        doc.close()

    At first I tried to make a FillLayer but I realized it's not a paint layer. Then I tried to merge a paintLayer down on the fillLayer but it happens mergeDown makes krita crash. See issue 419093 Not only that but a newly created FillLayer will appear transparent until I toggle it's visibility by hand (refreshProjection and scripted setVisible won't work)

    Edited by Manga Tengu
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment