Files
Export-Krita-Layers-As-Numb…/export_layer_as_numbered_files.py

35 lines
1.3 KiB
Python

from krita import *
import os
active_document = Krita.instance().activeDocument()
working_directory = os.path.dirname(active_document.fileName())
# change the "exported_layers" to whatever folder name you want
export_directory = os.path.join(working_directory, "exported_layers")
if not os.path.isdir(export_directory):
os.makedirs(export_directory)
Krita.instance().setBatchmode(True)
for index, node in enumerate(active_document.topLevelNodes()):
if node.name().lower() in ["background", "references"]:
continue
InfoObject().setProperty("alpha", True)
InfoObject().setProperty("compression", 9)
InfoObject().setProperty("forceSRGB", False)
InfoObject().setProperty("indexed", False)
InfoObject().setProperty("interlaced", False)
InfoObject().setProperty("saveSRGBProfile", False)
InfoObject().setProperty("transparencyFillcolor", [0,0,0])
base_name = os.path.splitext(os.path.basename(active_document.fileName()))[0]
file_name = f"{base_name}_{index-1:04}_{node.name()}.png"
path = os.path.join(export_directory, file_name)
node.save(path, active_document.resolution(), active_document.resolution(), InfoObject())
print("Exported: ", file_name, "\n")
Krita.instance().setBatchmode(False)
print("Export Complete.")