beginner lesson 10

Filters

See what filters can be used and apply them to your image

Available filters

Krita has a lot of filters between the built-in ones, and the extra ones provided by the G'Mic library. With the filters API, you only have the internal filters available. To get a list of all the filters you can use, you can print them out from Python with this code.

Note

The filters API is still a work in progress. While it has some functionality, it is a bit limited and rough around the edges.

from krita import *

print(Krita.instance().filters())

The output will contain an array of strings that contain the IDs for all the filters that can be applied. Let's see how to apply one next.

Apply a filter

We have a list of IDs of filters we can apply. Let's apply the "sharpen" filter from the list. This is how we would apply it to a layer.

from krita import *

application = Krita.instance()
currentDoc = application.activeDocument()
currentLayer = currentDoc.activeNode()

# grab the filter to work with
sharpenFilter = application.filter('sharpen')

# apply( layer, x, y, width, height  )
sharpenFilter.apply(currentLayer, 0, 0, 1280, 720)
currentDoc.refreshProjection()  # update UI

Manually configuring filters

While some filters don't require any settings, most do. Each filter has its own configuration object. This configuration object can be updated to change the results of the filter. Let's see how to grab the configuration object and update a few properties before applying it.

from krita import *

application = Krita.instance()
currentDoc = application.activeDocument()
currentLayer = currentDoc.activeNode()

noiseFilter = application.filter('noise')
noiseFilterConfig = noiseFilter.configuration()

# show available properties you can modify
print( noiseFilterConfig.properties() )

# update a couple of the properties
noiseFilterConfig.setProperty('opacity', 255)
noiseFilterConfig.setProperty('level', 13)
noiseFilter.setConfiguration(noiseFilterConfig)

#see existing config property
print( noiseFilterConfig.property('level') )

# apply filter to layer
noiseFilter.apply(currentLayer, 0, 0, currentDoc.width(), currentDoc.height())
currentDoc.refreshProjection()

Grabbing this configuration will work sometimes depending on the filter. There are currently still some bugs though. For example, if you try to grab the configuration option for the 'halftone' filter, Scripter will give an error that it cannot convert a KoColor to python. As scripting mature in Krita, this issue will be fixed. This page will be updated whenever fixes or changes happen with the filter API.

Have questions, need help, or find a typo?

Head to the Krita artists where we have a dedicated area for plugin development and give any feedback you might have.

;