Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp 3 Python Script - Merge Visible - No Flatten Image?
#1
Not sure if this is a problem with the documentation or if it's a bug, maybe someone here can shed some light.

I'm converting my Gimp 2 scripts to Gimp 3 and noticed that in v3 there is a new merge type listed in the docs for the description of:
gimp-image-merge-visible-layers

Under the parameters it lists:

Quote:The type of merge { EXPAND-AS-NECESSARY (0), CLIP-TO-IMAGE (1), CLIP-TO-BOTTOM-LAYER (2), FLATTEN-IMAGE (3) }, default EXPAND-AS-NECESSARY (0)


However calling gimp-image-merge-visible-layers , like so:


Code:
layer = merge_visible(img, Gimp.MergeType.FLATTEN_IMAGE)


Where merge_visible looks like this:


Code:
def merge_visible(image: Gimp.Image, merge_type: Gimp.MergeType = Gimp.MergeType.EXPAND_AS_NECESSARY)->Gimp.Layer:
    """
    Merge the visible layers of an image into a single layer.
    This procedure combines the visible layers into a single layer using the specified merge type.
    A merge type of EXPAND_AS_NECESSARY expands the final layer to encompass the areas of the visible layers.
    A merge type of CLIP_TO_IMAGE clips the final layer to the extents of the image.
    A merge type of CLIP_TO_BOTTOM_LAYER clips the final layer to the size of the bottommost layer.

    :param image: Gimp image with the layers to be merged
    :param merge_type: the type of merge:
        0 = Expand as Necessary
       1 = Clip to image
        2 = clip to bottom
        3 = Flatten Image

        default = Expand as Necessary
    :return: The merged layer
    """
    procedure = Gimp.get_pdb().lookup_procedure('gimp-image-merge-visible-layers')
    config = procedure.create_config()
    config.set_property('image', image)
    config.set_property('merge-type', merge_type)
    result = procedure.run(config)
    success = result.index(0)
    layer = result.index(1)
    return layer


However this results in an error:


Quote:GIMP-Error: Calling error for procedure 'gimp-image-merge-visible-layers':

Procedure 'gimp-image-merge-visible-layers' has been called with value 'GIMP_FLATTEN_IMAGE' for argument 'merge-type' (#2, type GimpMergeType). This value is out of range.

Thanks,
Jordan
Reply
#2
You can use image.flatten().
Reply
#3
Thanks but I'm not trying to flatten an image.

I was porting my code and noticed that the python console browser listed a new option for the gimp-image-merge-visible-layers procedure, so I thought I'd experiment and try the new option just to see the results, however whether passing the enum value of Gimp.MergeType.FLATTEN_IMAGE or just an int value of 3, I get the error above.

So my question was whether this looks like a bug in Gimp or an error in the documentation.
Reply
#4
layer = Gimp.Image.merge_visible_layers(img, Gimp.MergeType.CLIP_TO_IMAGE)
Reply
#5
I'm not trying to do something specific, I'm trying to determine if there is a bug in gimp so I can report it or if there's an error in the documentation so I can report it, well if possible.

Screenshot should be here but it says too much data even though it's just 26k

Look at the  Gimp 3  python browser, look up merge-visible-layers.  Note the parameters for merge type.

Note also there is an enum value in the MergeType object called FLATTEN_IMAGE

However passing that enum value, or the equivalent integer shown in the browser documentation, the result is the following error.


Quote:GIMP-Error: Calling error for procedure 'gimp-image-merge-visible-layers':

Procedure 'gimp-image-merge-visible-layers' has been called with value 'GIMP_FLATTEN_IMAGE' for argument 'merge-type' (#2, type GimpMergeType). This value is out of range.

So it would seem either the docs are incorrect or there is a bug.
Reply
#6
(Yesterday, 02:47 PM): silenuznowan Wrote: I'm not trying to do something specific, I'm trying to determine if there is a bug in gimp so I can report it or if there's an error in the documentation so I can report it, well if possible.

Screenshot should be here but it says too much data even though it's just 26k

Look at the  Gimp 3  python browser, look up merge-visible-layers.  Note the parameters for merge type.

Note also there is an enum value in the MergeType object called FLATTEN_IMAGE

However passing that enum value, or the equivalent integer shown in the browser documentation, the result is the following error.


Quote:GIMP-Error: Calling error for procedure 'gimp-image-merge-visible-layers':

Procedure 'gimp-image-merge-visible-layers' has been called with value 'GIMP_FLATTEN_IMAGE' for argument 'merge-type' (#2, type GimpMergeType). This value is out of range.

So it would seem either the docs are incorrect or there is a bug.

You are inferring that because an API accepts an enumeration, all the values of the enumeration are valid for the API. 

This is not true.

There are other examples: Gimp.context_set_paint_mode () takes a Gimp.LayerMode, and so does Gimp.Layer.set_mode(). But Gimp.Layer.set_mode() won't accept Gimp.LayerMode.BEHIND or Gimp.LayerMode.BEHIND_LEGACY that can only be used for painting, and presumably neither of them will accept Gimp.LayerMode.REPLACE which is specific to GEGL filters.
Reply
#7
(Yesterday, 09:24 PM)Ofnuts Wrote:
(Yesterday, 02:47 PM): silenuznowan Wrote: I'm not trying to do something specific, I'm trying to determine if there is a bug in gimp so I can report it or if there's an error in the documentation so I can report it, well if possible.

Screenshot should be here but it says too much data even though it's just 26k

Look at the  Gimp 3  python browser, look up merge-visible-layers.  Note the parameters for merge type.

Note also there is an enum value in the MergeType object called FLATTEN_IMAGE

However passing that enum value, or the equivalent integer shown in the browser documentation, the result is the following error.


Quote:GIMP-Error: Calling error for procedure 'gimp-image-merge-visible-layers':

Procedure 'gimp-image-merge-visible-layers' has been called with value 'GIMP_FLATTEN_IMAGE' for argument 'merge-type' (#2, type GimpMergeType). This value is out of range.

So it would seem either the docs are incorrect or there is a bug.

You are inferring that because an API accepts an enumeration, all the values of the enumeration are valid for the API. 

This is not true.

There are other examples: Gimp.context_set_paint_mode () takes a Gimp.LayerMode, and so does Gimp.Layer.set_mode(). But Gimp.Layer.set_mode() won't accept Gimp.LayerMode.BEHIND or Gimp.LayerMode.BEHIND_LEGACY that can only be used for painting, and presumably neither of them will accept Gimp.LayerMode.REPLACE which is specific to GEGL filters.

I'm not inferring anything, the documents explicitly state it as a valid parameter for MergeType.  That's the point.
Reply


Forum Jump: