Given the question marks, you haven't really understood how my procedure works. The fundamental idea is that your source image hasn't enough contrast to do a useful color-erase. But we can;
1) make a copy of that layer and increase the contrast on it so that the background becomes white
2) color-erase the background on that over-contrasted copy.
We now have a cut-out, over-contrasted image and the initial image. We wan to transfer the transparency of the over-contrasted image to the initial image, so
3) create a selection from the opacity of the cut-out image (in the UI, that's Alpha to selection, but in a script, that's gimp_select_item(layer))
4) use the selection to create a layer mask for the initial image
Then we are done, we just need to
5) erase the over-contrasted image, that has served its purpose.
6) export the image to file (in a format that supports transparency, so PNG or WEBP).
As to your code:
1) please remove any reference to me, that's your code...
2) no need to fetch the active drawable since this is exactly what is passed to you as the layer argument.
3) when you duplicate the layer, the function returns a reference to the copy, keep it safely, it will be useful later
4) brightness-contrast needs two plain numbers, you use brightness and contrast variables out of the blue...
1) make a copy of that layer and increase the contrast on it so that the background becomes white
2) color-erase the background on that over-contrasted copy.
We now have a cut-out, over-contrasted image and the initial image. We wan to transfer the transparency of the over-contrasted image to the initial image, so
3) create a selection from the opacity of the cut-out image (in the UI, that's Alpha to selection, but in a script, that's gimp_select_item(layer))
4) use the selection to create a layer mask for the initial image
Then we are done, we just need to
5) erase the over-contrasted image, that has served its purpose.
6) export the image to file (in a format that supports transparency, so PNG or WEBP).
As to your code:
1) please remove any reference to me, that's your code...
2) no need to fetch the active drawable since this is exactly what is passed to you as the layer argument.
3) when you duplicate the layer, the function returns a reference to the copy, keep it safely, it will be useful later
4) brightness-contrast needs two plain numbers, you use brightness and contrast variables out of the blue...