1

Suppose I want to copy the red channel of an image (thus creating a new channel). How do I do that with Python-Fu?

EDIT: basically, I need to create luminosity masks. So far, I tryed the following code:

# get active layer
layer = pdb.gimp_image_get_active_layer(image)
# copy the selected layer
layer_copy = pdb.gimp_layer_new_from_drawable(layer, image)
# insert the layer_copy on top of the layers stack
pdb.gimp_image_insert_layer(image, layer_copy, None, 0)
# desaturate the layer
pdb.gimp_drawable_desaturate(layer_copy, DESATURATE_LIGHTNESS)
# select the red channel
ch = pdb.gimp_channel_new_from_component(image, 0, "testchannel")
pdb.gimp_image_insert_channel(image, ch, 0, 1)

Unfortunately I got the error TypeError: wrong parameter type on the last command pdb.gimp_image_insert_channel(image, ch, 0, 1)

0

Your third argument should be None:

pdb.gimp_image_insert_channel(i, c, None,0)

The doc is mostly written with the script-fu point if view, where items are just integer ids, and "no item" is therefore 0. In python-fu, you pass object references, so "no item" is None.

You can do the same thing more simply (but with a bit less control) using:

image.insert_channel(channel)

Btw, you can also look at the python-fu object methods, using image.active_layer is a lot more readable than pdb.gimp_image_get_active_layer(image).

0

The R/G/B channels you see at the top of the Channels list are somewhat virtual since they are the result of the composition of the layers.

To get a layer with only the red component you can use the channel mixer:

pdb.plug_in_colors_channel_mixer(img, l, False, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

(note that it changes the layer it is called with, so you may want to do a copy first).

  • Thanks for the current answer, I should have been more specific with my question, which I now edited. Hope you understand what I'm trying to do.... – Davide_sd Jan 8 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.