Hi David.To consider:
You have a slight inconsistency in your code execution
If use "Stretch Contrast: No " orginal layer remains (and as far as possible should always remain)
If use "Stretch Contrast: Yes" orginal layer is deleted
You can replace line 144 - 146
pdb.gimp_image_remove_layer(image, layer)
name =pdb.gimp_drawable_set_name(layer_copy1, name)
to:
if stretch == "No":
pdb.gimp_image_remove_layer(image, layer_copy1)
# name =pdb.gimp_drawable_set_name(layer_copy1, name)
However, a better solution would be to include work on multiple layers (for the selected active layer):
If use "Stretch Contrast: Yes" the layers structure is correct
If use for layers "Stretch Contrast: No" the layer structure is incorrect
Requires moving the layer_copy1 to the top before executing the actual code
behind the line:
pdb.gimp_image_insert_layer(image,layer_copy1,None,0) # insert layer
add
if stretch == "No":
pdb.gimp_image_raise_item_to_top(image, layer_copy1)
and delete two lines:
pdb.gimp_image_remove_layer(image, layer_copy1)
name =pdb.gimp_drawable_set_name(layer_copy1, name)