GIMP Chat
http://gimpchat.com/

Unable to export jpg after added a new layer
http://gimpchat.com/viewtopic.php?f=9&t=19638
Page 1 of 1

Author:  ecs1749 [ Mon Oct 04, 2021 10:50 am ]
Post subject:  Unable to export jpg after added a new layer

I did the following

pdb.file_jpeg_save(image, drawable, filename, raw_filename, quality, smoothing, optimize, progressive, ...))
pdb.gimp_image_add_layer(image, imagLayer, 0)
pdb.file_jpeg_save(image, drawable, filename, raw_filename, quality, smoothing, optimize, progressive, ...))

The first save ran without any issue but after I added a layer, I am unable to save it again. I got a message:

Calling error for procedure 'file-jpeg-save':
Procedure 'file-jpeg-save' has been called with an invalid ID for argument 'drawable'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.

It sounds like I need a new drawable after added a new layer,

But how do I do that?

Author:  ofnuts [ Mon Oct 04, 2021 12:06 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

The file-*-save procedure do not save the image, they save a layer. What happened in your case is likely that the initial layer is no more. If you merged things (gimp_image_flatten(), gimp_image_merge_down() and a few others) the result is a new layer, but the call returns the layer created. So you just have to keep that returned value.

If your image still has several layers at the end, instead of flattening you can also use gimp_layer_new_from_visible() and save the returned layer.

Author:  Pocholo [ Mon Oct 04, 2021 12:09 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

You need to create a new layer first before you add or insert the layer.
    layer = pdb.gimp_layer_new(image, width, height, type, name, opacity, mode) #Give the layer another name other than drawable

Author:  ecs1749 [ Mon Oct 04, 2021 12:55 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

ofnuts wrote:
The file-*-save procedure do not save the image, they save a layer. What happened in your case is likely that the initial layer is no more. If you merged things (gimp_image_flatten(), gimp_image_merge_down() and a few others) the result is a new layer, but the call returns the layer created. So you just have to keep that returned value.

If your image still has several layers at the end, instead of flattening you can also use gimp_layer_new_from_visible() and save the returned layer.


Thank you for the response.

I guessed that much. In fact, after the post, I did a pdb.gimp_image_merge_down to get a new layer but pdb.file_jpeg_save doesn't take layers as a parameter.

pdb.file_jpeg_save(image, drawable, filename, raw_filename, quality, smoothing, optimize, progressive, comment, subsmp, baseline, restart, dct)

I tried

pdb.gimp_image_set_active_layer(image, newLayer)

and that doesn't do anything.


So what do I do with the returned layer?

Author:  Pocholo [ Mon Oct 04, 2021 2:23 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

to get the layer again that you merged. Are you using GIMP's PPB or PDB? The procedure Browser is your best friend!
layer = pdb.gimp_image_get_layer_by_name(image, name)

Author:  ecs1749 [ Mon Oct 04, 2021 3:01 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

Pocholo wrote:
to get the layer again that you merged. Are you using GIMP's PPB or PDB? The procedure Browser is your best friend!
layer = pdb.gimp_image_get_layer_by_name(image, name)


I have the new_layer returned by several procedures I tried. That's not the problem.

What do I do with it? pdb.file_jpeg_save doesn't accept layer as a parameter.

Author:  Pocholo [ Mon Oct 04, 2021 3:53 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

ecs1749 wrote:
Pocholo wrote:
to get the layer again that you merged. Are you using GIMP's PPB or PDB? The procedure Browser is your best friend!
layer = pdb.gimp_image_get_layer_by_name(image, name)


I have the new_layer returned by several procedures I tried. That's not the problem.

What do I do with it? pdb.file_jpeg_save doesn't accept layer as a parameter.


pdb.gimp_image_flatten(image) #returns the layer object which is the result of the flattening and can be used for the save.

Author:  ecs1749 [ Mon Oct 04, 2021 4:12 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

Pocholo wrote:
ecs1749 wrote:
Pocholo wrote:
to get the layer again that you merged. Are you using GIMP's PPB or PDB? The procedure Browser is your best friend!
layer = pdb.gimp_image_get_layer_by_name(image, name)


I have the new_layer returned by several procedures I tried. That's not the problem.

What do I do with it? pdb.file_jpeg_save doesn't accept layer as a parameter.


pdb.gimp_image_flatten(image) #returns the layer object which is the result of the flattening and can be used for the save.


I am having trouble communicating. We are going back and forth without progress. You said " can be used for the save". My point is "pdb.file_jpeg_save doesn't accept layer as a parameter". So, if it doesn't accept layer as a parameter, how does it "used for the save"? It accepts drawable as parameter but not layer.

Author:  ofnuts [ Mon Oct 04, 2021 6:59 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

ecs1749 wrote:
ofnuts wrote:
The file-*-save procedure do not save the image, they save a layer. What happened in your case is likely that the initial layer is no more. If you merged things (gimp_image_flatten(), gimp_image_merge_down() and a few others) the result is a new layer, but the call returns the layer created. So you just have to keep that returned value.

If your image still has several layers at the end, instead of flattening you can also use gimp_layer_new_from_visible() and save the returned layer.


Thank you for the response.

I guessed that much. In fact, after the post, I did a pdb.gimp_image_merge_down to get a new layer but pdb.file_jpeg_save doesn't take layers as a parameter.

pdb.file_jpeg_save(image, drawable, filename, raw_filename, quality, smoothing, optimize, progressive, comment, subsmp, baseline, restart, dct)

I tried

pdb.gimp_image_set_active_layer(image, newLayer)

and that doesn't do anything.


So what do I do with the returned layer?


Of course it does. A layer is a drawable (a drawable is a layer, a channel or a mask), so the "drawable" parameter should be the layer returned by pdb.gimp_image_merge_down().

Author:  Pocholo [ Mon Oct 04, 2021 7:17 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

I think you should read the GIMP Python Documentation

Author:  ecs1749 [ Mon Oct 04, 2021 7:49 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

ofnuts wrote:
ecs1749 wrote:
ofnuts wrote:
The file-*-save procedure do not save the image, they save a layer. What happened in your case is likely that the initial layer is no more. If you merged things (gimp_image_flatten(), gimp_image_merge_down() and a few others) the result is a new layer, but the call returns the layer created. So you just have to keep that returned value.

If your image still has several layers at the end, instead of flattening you can also use gimp_layer_new_from_visible() and save the returned layer.


Thank you for the response.

I guessed that much. In fact, after the post, I did a pdb.gimp_image_merge_down to get a new layer but pdb.file_jpeg_save doesn't take layers as a parameter.

pdb.file_jpeg_save(image, drawable, filename, raw_filename, quality, smoothing, optimize, progressive, comment, subsmp, baseline, restart, dct)

I tried

pdb.gimp_image_set_active_layer(image, newLayer)

and that doesn't do anything.


So what do I do with the returned layer?


Of course it does. A layer is a drawable (a drawable is a layer, a channel or a mask), so the "drawable" parameter should be the layer returned by pdb.gimp_image_merge_down().


LOFL! Is it that obvious? Great help! I completed my first plugin. I am very comfortable with Python. I just need to get familiar with GIMP specific details.

Thanks for all the help, folks.

Author:  ofnuts [ Tue Oct 05, 2021 2:24 am ]
Post subject:  Re: Unable to export jpg after added a new layer

ecs1749 wrote:
I am very comfortable with Python.


Then you should have found this:

>>> layer=gimp.image_list()[0].active_layer
>>> layer.__class__.__mro__
(<type 'gimp.Layer'>, <type 'gimp.Drawable'>, <type 'gimp.Item'>, <type 'object'>)

Author:  ecs1749 [ Tue Oct 05, 2021 2:54 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

ofnuts wrote:
ecs1749 wrote:
I am very comfortable with Python.


Then you should have found this:

>>> layer=gimp.image_list()[0].active_layer
>>> layer.__class__.__mro__
(<type 'gimp.Layer'>, <type 'gimp.Drawable'>, <type 'gimp.Item'>, <type 'object'>)


Alright. You got me stumped. I know syntactically what these statements are but how would they have helped me realize "Drawable" means I can pass the "layer" to it?

For me as a newbie, I thought it's a typo for "Drawtable"!!!

Author:  Skinnyhouse [ Tue Oct 05, 2021 3:59 pm ]
Post subject:  Re: Unable to export jpg after added a new layer

When I started scripting and got stuck on the 'eccentricities' of Gimp I found that looking at other people's code was a big help.

Author:  ofnuts [ Wed Oct 06, 2021 6:50 am ]
Post subject:  Re: Unable to export jpg after added a new layer

ecs1749 wrote:
ofnuts wrote:
ecs1749 wrote:
I am very comfortable with Python.


Then you should have found this:

>>> layer=gimp.image_list()[0].active_layer
>>> layer.__class__.__mro__
(<type 'gimp.Layer'>, <type 'gimp.Drawable'>, <type 'gimp.Item'>, <type 'object'>)


Alright. You got me stumped. I know syntactically what these statements are but how would they have helped me realize "Drawable" means I can pass the "layer" to it?

For me as a newbie, I thought it's a typo for "Drawtable"!!!


Well, if you know Python, you know some OOP. Types within types within types. If I tell you something takes a Collection, but you have a Set, you'll wonder if the Set is a Collection. In any case this isn't civil engineering, the cost of trying something is nearly zero. And since you already had case that worked, did you try to check the type of what was passed in that call?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/