Search code examples
pythongimppython-fu

gimp edit blend in python script produces different blend than the blend tool


I'm trying to write a script that re-sizes, moves and blends two images in one using gimp 2.8 on ubuntu 13.10.

I uploaded the 2 needed images and the results here: https://i.sstatic.net/s3dLg.jpg

I managed to get all to run but one point fails. the blending command. I reduced the problem to the pdb.gimp_edit_blend command which instead of blending the layer mask with the transparent background it creates an opaque gradient.

image = gimp.image_list()[0]  #image is 237x300 png like above
pdb.gimp_image_resize(image, 300, 300, -100, 0)
fg_layer = pdb.gimp_image_get_active_layer(image)
mask = pdb.gimp_layer_create_mask(fg_layer,ADD_WHITE_MASK)
pdb.gimp_image_add_layer_mask(image, fg_layer, mask)

# from here it goes wrong, if I skip this step than I can get the correct result
# using the gimp blent tool from the gui using the same settings as here
pdb.gimp_edit_blend(fg_layer, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_LINEAR, 100, 0, 0, True, False, 0, 0, True, 0, 150, 150, 150)

the whole code is here: http://pastie.org/9079343

any idea what I'm doing wrong? thanks a lot


Solution

  • Your error is pretty much in your own code - you are calling the blending function passing the fg_layer as the first parameter, instead of the mask:

    pdb.gimp_edit_blend(fg_layer, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_LINEAR, 100, 0, 0, True, False, 0, 0, True, 0, 150, 150, 150)
                        ^^^^^^^^
    

    Instead, do the same call passing the mask as the drawable parameter (you already have it in the "mask" variable):

    pdb.gimp_edit_blend(mask, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_LINEAR, 100, 0, 0, True, False, 0, 0, True, 0, 150, 150, 150)