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

[Solved] Problem with SetColorSpace in python script

Tags: None
(comma "," separated)
luuk
Registered Member
Posts
2
Karma
0
I need to convert images from RGB to CMYK for a publication. The results I get with Krita are better than the results with ImageMagick. Because i have a lot of images to convert, I tried to write a python script.
When I convert to CMYKA using the script the resulting profile is always 'Chemical Proof'.
When I convert to CMYKA using Krita, Image, Convert image Color Space the result uses the selected profile.
When converting to a RGB profile the result is usually right.
Can anybody help me to improve my script.

This is my script
Code: Select all
#==========
# setColorSpace.py
# setClorSpace to FOGRA39L for all files in a directory
#
#==========

import glob
import os
from krita import *

os.chdir( '/data/SLN/blad-nieuw/blad-2022-06/collection-test/images' )

cmyk_dir = ("CMYK")
dir_present = os.path.isdir(cmyk_dir)

if not dir_present:
    os.makedirs(cmyk_dir)
    print( "Directory" + cmyk_dir + " created")

else:
    print("Directory " + cmyk_dir + " exists")

counter = 0
extensions = [ '.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG' ]
files = []
for file in glob.glob("*.*"):
    files.append(file)

for name in files:
    file_name, file_ext = os.path.splitext( name )
#    print( name, file_name, file_ext )
    if file_ext in extensions:
        counter = counter + 1

        print( str( counter) + ' Start ' + name )

        instance = Krita.instance()
        document = instance.openDocument( name )
        document.waitForDone()
        document.flatten()
        document.waitForDone()

        document.setBatchmode(True)

        print( "  Input" )
        print( "    color depth  : " + document.colorDepth() )
        print( "    color model  : " + document.colorModel() )
        print( "    color profile: " + document.colorProfile() )

#        result = document.setColorSpace( "RGBA", "U8", "WideRGB-elle-V2-g22.icc")
        result = document.setColorSpace( "CMYKA", "U8", "FOGRA39L_coated.icc")
#        result = document.setColorSpace( "LABA", "U8", "Lab-D50-Identity-elle-V4.icc")
        if result:
            print( "  Result setColorSpace: True" )
        else:
            print( "  Result setColorSpace: False" )
        document.waitForDone()
        print( "  Output" )
        print( "    color depth  : " + document.colorDepth() )
        print( "    color model  : " + document.colorModel() )
        print( "    color profile: " + document.colorProfile() )

        document.saveAs( "/data/SLN/blad-nieuw/blad-2022-06/collection-test/images/CMYK/" + file_name + ".tif" )
        document.waitForDone()
        document.close()
        document.waitForDone()
        print( str( counter) + ' Ready ' + name )
        if counter >= 1:
            print( 'break' )
            break
       
print( "Converted " + str(counter) + " files")

The result is:
Code: Select all
Directory CMYK exists
1 Start DSC_2541.jpg
  Input
    color depth  : U8
    color model  : RGBA
    color profile: sRGB-elle-V2-srgbtrc.icc
  Result setColorSpace: True
  Output
    color depth  : U8
    color model  : CMYKA
    color profile: Chemical proof
1 Ready DSC_2541.jpg
break
Converted 1 files

Last edited by luuk on Fri Jun 03, 2022 6:14 pm, edited 1 time in total.
luuk
Registered Member
Posts
2
Karma
0
I found the error in the script. In setColorSpace the third parameter is not the name of the color profile file (FOGRAL_coated.icc) but the name of the color profile in Krita as shown in the dialog Convert Image Color Space, in this case "FOGRA39L Coated".


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell