Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Python-fu gimp_drawable_levels(): "TypeError: wrong parameter type"

Tue Nov 16, 2021 11:36 pm

Posted this as a bug, but I'm not sure if it is a bug. I just rediscovered this forum, so hoped I could get an answer here.

Environment/Versions

GIMP version:
AppImage 2.10.22 with plugins
Linux Mint 20.2


Description of the bug
I can't find out how to use python-fu command gimp_drawable_levels. I think I've got everything correct, but the error message is unhelpful, and I don't know what to change. I suspect it's a bug, but have found so little documentation regarding this feature that I can't be sure I'm using it right.

Reproduction
Is the bug reproducible? Always.
Reproduction steps:

open python-fu console
paste this:

from gimpfu import *

input_path = '/path/to/input.png'
output_path = '/path/to/output.png'
image = pdb.gimp_file_load(input_path, input_path)

# red
pdb.gimp_drawable_levels(
image,
HISTOGRAM_RED,
0.050980392156862744,
0.95686274509803926,
False,
1.0,
0.0,
1.0,
False
)

Expected result:
no error
Actual result:
Traceback (most recent call last):
File "", line 10, in
TypeError: wrong parameter type

Re: Python-fu gimp_drawable_levels(): "TypeError: wrong parameter type

Wed Nov 17, 2021 1:39 am

Hi Ipsod.
pdb.gimp_drawable_levels(drawable, channel, low_input, high_input, clamp_input, gamma, low_output, high_output, clamp_output)
You should use 'layer' not 'image'

Re: Python-fu gimp_drawable_levels(): "TypeError: wrong parameter type

Thu Nov 18, 2021 4:59 am

MareroQ wrote:Hi Ipsod.
pdb.gimp_drawable_levels(drawable, channel, low_input, high_input, clamp_input, gamma, low_output, high_output, clamp_output)
You should use 'layer' not 'image'


To be more accurate, since your loaded image has a single layer, you can obtain the drawable from your image using either "image.active_drawable" or "image.layers[0]".

This said, since it looks like you want to process files in batch, you should really look at ImageMagick, which is designed to be used in shell scripts. You possibly want to explore "-level-colors {black_color}{,}{white_color}" together with "-channel type".
Post a reply