This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Help with Python scripting

Tags: None
(comma "," separated)
alexwb
Registered Member
Posts
3
Karma
0

Help with Python scripting

Sun Jul 28, 2019 6:58 pm
I can't find a guide to Krita's API in Python.

What I want to do is group several frames into three layers of animation. Then render the animation and save (png frames combined) and the document in .kra format.

The python part to collect frames it's easy to me; but couldn't find a suitable source for Krita API in python for all the things I need (create layer, import frames in layer, hide layer, render animation and finally save the kra document).

This is how far I went:


Code: Select all
import os
from krita import *
path = '/path/to/frame/sources'
base_name = "run"
layer_col = []
layer_line = []
layer_ref = []
for r, d, f in os.walk(path):
    for file in f:
        if 'col0' in file:
            layer_col.append(os.path.join(r, file))
        elif 'lineart0' in file:
            layer_line.append(os.path.join(r, file))
        elif 'ref' in file:
            layer_ref.append(os.path.join(r, file))
layer_line.sort()
layer_col.sort()
layer_ref.sort()
animation_size=len(layer_line)


To be clear, if I print the content of all three array I get something like this:

Code: Select all
/path/to/frame/sources/col0001.png
/path/to/frame/sources/col0002.png
/path/to/frame/sources/col0003.png
/path/to/frame/sources/col0004.png
/path/to/frame/sources/col0005.png
/path/to/frame/sources/col0006.png
/path/to/frame/sources/col0007.png
/path/to/frame/sources/col0008.png
/path/to/frame/sources/col0009.png
/path/to/frame/sources/col0010.png
/path/to/frame/sources/ref0001.png
/path/to/frame/sources/ref0002.png
...[cut]



While this is the pseudo-code I was thinking to use:

Code: Select all
#create layer named "lineart"
    #import animation frames from files in array [layer_line]
#repeat for a layer named "flat colors" from files in array [layer_col]
#repeat for a layer named "reference" from files in array [layer_ref]
#hide layer "reference"
#render animation:
    #first frame = 0
    #last frame = [animation_size]
    #file format = png
    #path = /path/to/render
    #base name = [base_name]
#save file: [path]+[base_name]+".kra"
User avatar
scottpetrovic
Registered Member
Posts
520
Karma
4
OS

Re: Help with Python scripting

Sun Jul 28, 2019 7:12 pm
I think all that sounds pretty doable... Did you check out the documentation the docs site?

https://docs.krita.org/en/user_manual/p ... rita-s-api

it also has a couple links to the classes with the API.

https://api.kde.org/extragear-api/graph ... index.html
https://api.kde.org/extragear-api/graph ... Krita.html

For an example with importing frames, you could see a plugin I wrote a bit ago that creates an images sequence from a video file and imports it into Krita .

Animator video reference
https://github.com/scottpetrovic/animat ... -reference
(this file has almost all the python code https://github.com/scottpetrovic/animat ... mporter.py)


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]