Krita API / CommandLine Interface

Hi,
I am trying to export .kra files from the commandline using “–export” but I ran into problems. It seems to randomly fail, or rather it randomly works 1 out of 10 times. The TaskManager shows krita.exe working but it seems to just crash/shut down without a result. Sometimes though it creates the .png file just fine, very strange.

This is the command I use:
"krita test.kra --export --export-filename test.png"
or more precisely
"C:\Program Files\Krita (x64)\bin\krita" test.kra --export --export-filename test.png

I have recorded the behaviour in a short video:

In the video I execute the command two times. The first time it works, the second time it does not (keeps failing afterwards).

Krita Version as reported by “-v” is 4.4.3.
I am on a Windows 10 System.

Is there some sort of “verbose” flag which I can use to dig into this?
Or maybe some direction towards the relevant source code would help too.

Any help would be appreciated,
Thank you.

Hi

To get output to terminal, you have to execute command line from cygwin or git bash for example (cmd or powershell terminal doesn’t output Krita’s warnings&error)

Example:

You can also try to redirect output in a file:

krita.exe -v > test.txt

Grum999

I did noticed that even when using git bash, the output of Krita on Windows is just simply not put into stderr (since I know it works on Windows just fine, because I was developing on Windows before) but something else. So to see Krita’s extended output, you need to download a program called DebugView and enable it before trying Krita. There is also some info in Krita log - the easiest way to access it is to run Krita in GUI and check Help → Show Krita log for bug reports, but you can just open relevant files. See Getting Krita logs — Krita Manual 4.4.0 documentation

Thanks a lot for your quick replies. Will try your suggestions and report back :slight_smile:

Update1: Quick update, here is the complete log of -v redirected to a file:

*** EGL colorSpace: 0x308A
*** EGL format: 0x93A1
*** Native format: 0x57
*** EGL colorSpace: 0x308A
*** EGL format: 0x93A1
*** Native format: 0x57
*** EGL colorSpace: 0x308A
*** EGL format: 0x93A1
*** Native format: 0x57
*** EGL colorSpace: 0x308A
*** EGL format: 0x93A1
*** Native format: 0x57

Update2: Just to confirm @tiar s observation. I am using the Linux subsystem for Windows (usually for ssh, rsync etc.). It does not seem to return any error logs. Can try cygwin or gitbash too but I don’t think it will yield any different results. Will try the Krita logs as described in the manual next.
Here is another video using the bash:

Updates 3: Got the Krita Logs for a success case and an error case (though the error case seems to just do nothing). %LOCALAPPDATA%\kritacrash.log has no content (file does not exists). I assume there was no error log written.

Success Log:

SESSION: 03 May 2021 16:48:36 +0200. Executing C:\Program Files\Krita (x64)\bin\krita.exe

Krita Version: 4.4.3, Qt version compiled: 5.12.9, loaded: 5.12.9. Process ID: 9800
-- -- -- -- -- -- -- --
03 May 2021 16:48:36 +0200: Style: fusion. Available styles: windowsvista, Windows, Fusion

SESSION: 03 May 2021 16:49:55 +0200. Executing krita.exe test.kra --export --export-filename test.png

Krita Version: 4.4.3, Qt version compiled: 5.12.9, loaded: 5.12.9. Process ID: 15348
-- -- -- -- -- -- -- --
03 May 2021 16:49:55 +0200: Style: fusion. Available styles: windowsvista, Windows, Fusion
03 May 2021 16:50:01 +0200: Importing application/x-krita to application/x-krita. Location: C:/dev/KritaForUnity/Krita/Textures/test.kra. Real location: C:/dev/KritaForUnity/Krita/Textures/test.kra. Batchmode: 1
03 May 2021 16:50:01 +0200: Loaded image from application/x-krita. Size: 1024 * 1024 pixels, 1.38889 dpi. Color model: 8-bit integer/channel RGB/Alpha (sRGB-elle-V2-srgbtrc.icc). Layers: 4
03 May 2021 16:50:01 +0200: Converting from application/x-krita to image/png. Location: test.png. Real location: test.png. Batchmode: 1. Configuration: <!DOCTYPE params>
<params>
 <param name="ColorDepthID" type="string"><![CDATA[U8]]></param>
 <param name="ColorModelID" type="string"><![CDATA[RGBA]]></param>
 <param name="ImageContainsTransparency" type="internal">false</param>
 <param name="alpha" type="string"><![CDATA[true]]></param>
 <param name="compression" type="string"><![CDATA[3]]></param>
 <param name="forceSRGB" type="string"><![CDATA[true]]></param>
 <param name="indexed" type="string"><![CDATA[false]]></param>
 <param name="interlaced" type="string"><![CDATA[false]]></param>
 <param name="sRGB" type="internal">true</param>
 <param name="saveAsHDR" type="string"><![CDATA[false]]></param>
 <param name="saveSRGBProfile" type="string"><![CDATA[false]]></param>
 <param name="storeAuthor" type="string"><![CDATA[false]]></param>
 <param name="storeMetaData" type="string"><![CDATA[false]]></param>
 <param name="transparencyFillcolor" type="string"><![CDATA[<!DOCTYPE color>
<color>
 <RGB g="1" r="1" b="1" space="sRGB-elle-V2-g10.icc"/>
</color>
]]></param>
</params>

03 May 2021 16:50:02 +0200: CLOSING SESSION

“Error” Log:

SESSION: 03 May 2021 17:03:11 +0200. Executing krita.exe test.kra --export --export-filename test.png

Krita Version: 4.4.3, Qt version compiled: 5.12.9, loaded: 5.12.9. Process ID: 3332
-- -- -- -- -- -- -- --
03 May 2021 17:03:11 +0200: Style: fusion. Available styles: windowsvista, Windows, Fusion
03 May 2021 17:03:16 +0200: Importing application/x-krita to application/x-krita. Location: C:/dev/KritaForUnity/Krita/Textures/test.kra. Real location: C:/dev/KritaForUnity/Krita/Textures/test.kra. Batchmode: 1
03 May 2021 17:03:17 +0200: Loaded image from application/x-krita. Size: 1024 * 1024 pixels, 1.38889 dpi. Color model: 8-bit integer/channel RGB/Alpha (sRGB-elle-V2-srgbtrc.icc). Layers: 4
03 May 2021 17:03:17 +0200: CLOSING SESSION

It seems to just stop after loading the image (not export).

DebugView:

My question seems stupid but, if you try to open file from krita interface (no command line) and save it a PNG, it works?

If you try to convert from command line with another kra file, do you have the same problem?

Grum999

Hi, good question to ask (let’s get the obvious out of the way).
Yes, it works if I do it manually (open in krita and export).
Also it sometimes works with the commandline, that’s what I find really odd, because intially I though I had the command line parameters wrong but that does not seem to be the issue.

I will try with some other files but it really is just a very simple krita file:
kamgam dot com/krita/test.kra (the forum does not allow me to post this link?)

I will try some other files, just to be sure.

Update: Just tried with a very simple file (4 strokes with a brush) and it also fails.

That’s because you’re a new user, it’s an anti-spam defense. It’s annoying for help requests but quite good for preventing spam, actually.

I guess it would be good for someone to try to replicate it even on Linux, it looks as if Krita was closing before managing to finish the export… but without a crash. So it might be a bug.

I understand, thanks for unhiding it :slight_smile:

Should I create a bug report somewhere with a repro description?
Also, can you point me to the source code involved in this?
Maybe I can build it myself and fiddle around a little (not sure if I can find the time).

Here is some context on what I acutally need this for (maybe there is a different approach). I am trying to automate importing .kra files into the Unity3D game engine. It natively supports importing .psd files and I want to kinda have that for krita too. My approach is to have a dedicated folder with all the .kra files in it. That folder is observerd with a file watcher which detects if a file has changed and then automatically creates a .png from it and copies it over to Unity’s textures folder. Alas, it fails just when I need Krita to do the batch processing :-/

Anyhow, thank you for your help. I really appreciate it and did not expect to get such nice detailed answers so quickly.

1 Like

On my side I tested both Linux and Windows.

On Linux it works, file is converted on first execution each time (or I’m very lucky :slight_smile: )

On windows, it sometimes works, sometimes not.
In a powershell console; type command:

$i=0;while((test-path "c:\temp\test.png") -eq $False) { $i++; write-host $i; cmd /c "d:\Apps\krita-x64-4.4.3\bin\krita.exe c:\temp\test.kra --export --export-filename c:\temp\test.png"; }

File is produced after 3 or 4 or 5 or 12 attempts, it depends of I don’t know :man_shrugging:

Grum999

1 Like

Oh, thanks @Grum999 for giving it a try. I am currently knee deep in installing Linux Mint for testing, but I think I can skip that now :D. So it’s a windows only issue?

What I noticed is that the command returns immediately within cmd.exe but not in bash. So maybe it really is somehow stopping processing prematurely? Though, using bash on windows does not make it succeed any more often I think. Hm …

Using bash in windows doesn’t change anything
I used here a powershell command to do check because I’m used to with this scripting language but how you execute command line doesn’t really matter

Grum999

I have now tried it on Linux Mint/Debian too and can also confirm that it works just fine there. Though it prints some funny logs:

oem@geo-mint:~/Downloads$ ./krita443.appimage test.kra --export --export-filename text.png
NOT COOL: Duplicated action name from xml data:  "object_order_raise"
NOT COOL: Duplicated action name from xml data:  "object_align_horizontal_right"
NOT COOL: Duplicated action name from xml data:  "object_ungroup"
NOT COOL: Duplicated action name from xml data:  "object_order_back"
NOT COOL: Duplicated action name from xml data:  "object_order_front"
NOT COOL: Duplicated action name from xml data:  "object_align_vertical_center"
NOT COOL: Duplicated action name from xml data:  "object_group"
NOT COOL: Duplicated action name from xml data:  "object_align_horizontal_left"
NOT COOL: Duplicated action name from xml data:  "object_align_vertical_top"
NOT COOL: Duplicated action name from xml data:  "object_align_horizontal_center"
NOT COOL: Duplicated action name from xml data:  "object_order_lower"
... I shortened them because it's a long list ...
NOT COOL: Duplicated action name from xml data:  "execute_script_8"
NOT COOL: Duplicated action name from xml data:  "execute_script_9"
NOT COOL: Duplicated action name from xml data:  "execute_script_10"
NOT COOL: Duplicated action name from xml data:  "krita_filter_threshold"
krita.general: Warning: some tiles have leaked:
krita.general: 	Tiles in memory: 790 
 	Total tiles: 790