Skip to content

exporting data from krita (en)

nklbdev edited this page Sep 15, 2023 · 4 revisions

About importing data from Krita

en ru

Logo

Krita is a powerful application for raster graphics and animation, retouching and various image transformations. It also has some vector graphics features. It is built on the Qt framework and is a part of KDE. It supports the installation of various plugins and resources such as brushes and effects. It has an API for scripting in Python and a small CLI (command line interface) to export or convert files.

To work with animation in Krita there are dockers (parking windows):

  • Animation Timeline, which contains a table of layers and keyframes and playback controls;
  • Storyboard, where you can select multiple time ranges for different animations;
  • Onion Skins, on which you can set the degree of visibility of previous and subsequent frames to facilitate drawing movements.

Selecting a range of frames for playback is not very convenient: to do this, you need to click the Animation settings menu button and explicitly specify the numbers of the start and end frames. To simplify this process, I made a special plugin Storyboard timeline selector, which automatically selects the frames included in the story when you click on it with the left mouse button.

The duration of the "story" (the number of frames included in it) is not set in the most convenient way. It consists of the number of seconds and the number of residual frames. These numbers are directly related to the overall animation speed (frames per second) set.

In Krita, it is possible to export an animation to a sequence of image files via the File -> Render Animation menu. You can also do this from the command line:

> path/to/krita.com --export-sequence --export-filename <base_file_name>.<format_extension> path/to/source/file.kra

Attention! Krita exports vector layers from the GUI, but doesn't export from the command line interface.

In order not to have to manually call the export from Krita manually and then configure the import of its results into the Godot project, you can configure the import of *.kra files using Importality. To do this, in the project settings in the "Importality" section specify the directory of temporary files and configure the Krita command and its parameters using one of the methods given at the end of the article. Then select the *.kra file in the Godot file system tree, on the "Import" tab, select the desired import format, configure its parameters and click the "Reimport" button. If you change the import format, the engine may require a restart.

Unfortunately, in "stories" you cannot separately specify the direction of playback and the number of repetitions of the animation. Therefore, to specify these parameters, use the suffixes added at the end of the "story" name:

<animation_name> [-d:<direction>] [-r:<repeat_count>]

Where:

  • direction - animation direction. Possible values:
    • f (forward) - forward (default)
    • r (reverse) - back
    • pp (ping-pong) - forward and then back
    • ppr (ping-pong reverse) - first back and then forward
  • repeat_count - the number of repetitions of the animation (default 1). If set to 0, the animation will loop indefinitely

For example:

Idle -r:0
Walk -r:0
Jump -r:1
Crouch -r:1
Hurt -r:1
Die -r:1
Special -d:pp -r:0

Krita saves its projects in *.kra files. These are regular ZIP archives that contain metadata in XML-files and raster data in PNG-files and some other data. They also have a PNG thumbnail file named preview.png and a full size merged image file named mergedimage.png. Thus, to import a .kra file into the Godot engine as a regular image, no additional tools are needed. The plugin just needs to open the archive and extract the mergedimage.png file from it. But with the export of a sequence of frames, everything is more complicated.

Krita's little problem

Krita does not consider the document to have changed if you change the name or duration of the story in the Storyboard docker window. It also does not consider that the document has changed if you change the range of frames played and the animation speed. Pressing Ctrl+S will do nothing and Godot will not start re-importing your file.

To avoid this, make a change to the canvas (for example, make a brush stroke) and undo it. After that, saving the document will be available.

Krita's BIG PROBLEM

Firstly, to export a sequence of frames, it will not be possible to do without Krita itself, because only it can correctly combine all the data stored in the file and apply various transformations and effects to the results. Secondly, it is not possible to launch a second instance of Krita application while the first one is already running under this user profile.

Krita exclusively uses the SQLite database to manage its resources in its folder in the current user's profile. Krita allows you to create multiple windows, but they are all controlled by the same application instance. This will block the Krita console command to export frames, waiting until all Krita windows are closed.

But what if you draw a few more frames, save the file, and switch to the Godot window to immediately see the updated asset? The import will hang until you close Krita! Fortunately, there is a way out, although it is not the most convenient: make Godot run the Krita command as another user. To do this, different operating systems have different tools:

Windows:

Linux:

Mac OS:

Ready-to-use solutions

Windows:

  1. Create an additional user account in the operating system, such as KritaRunner.
    • To do this, open Start menu and type "run" on the keyboard or press Win+R. The application for running commands will open.
    • Type the command netplwiz and press Enter. The User Account Control window will open.
    • Add a new user. Opt out of creating a Microsoft account if you are prompted to do so. Choose to create a local account.
    • Enter a name of new user (preferably in Latin) and password.
    • Specify that the account is not created for an administrator, but for a regular user.
  2. Download and configure PowerShell Script to run the command as another user with saved credentials.
    • To do this, in Explorer, in the folder where you decided to place this script, place the cursor in the address bar and type "powershell" and press Enter. A PowerShell interpreter window will open with the current directory already selected.
    • Start typing the name of the script (the first few letters are enough) and press Tab one or more times until the full name of the script is appeared.
    • Add a space to the end of the line and then specify the file name to save the encrypted credentials, or, if necessary, the full path to it, and press Enter
    • The script will prompt you to enter a username and password. Enter the credentials of new user you just created.
    • The script will create a file with encrypted credentials. The PowerShell window can now be closed.
  3. Configure Godot to launch Krita with this script.
    • To do this, open the plugin settings in the project settings (Project Settings -> General -> Advanced Settings -> Importality)
    • For Krita Command, enter powershell
    • Expand the Krita Command Arguments array, and increase the number of elements to 4.
    • Specify command arguments (example in the screenshot below):
      • 0: -File
      • 1: full path to the script
      • 2: full path to the additional user's encrypted credentials file
      • 3: full path to the Krita executable (in the Krita installation folder, in the bin folder, there are krita.exe and krita.com files. It is better to choose krita.com, as it is adapted for work from the command line)
  4. That's it!. Now Godot will be able to run Krita as an additional user and pass it the necessary parameters for exporting frames from source files.

Settings

You will help the project a lot if you tell me how you can improve the script and how it integrates with the plugin!

Linux:

Solution development is planned.

You will help the project a lot if you develop this solution earlier!

MacOS:

Solution development is planned.

You will help the project a lot if you develop this solution earlier!

Clone this wiki locally