It is currently Tue Jul 02, 2024 2:22 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 10:50 am  (#1) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
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?


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 12:06 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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.

_________________
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 12:09 pm  (#3) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 12:55 pm  (#4) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
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?


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 2:23 pm  (#5) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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)

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 3:01 pm  (#6) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
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.


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 3:53 pm  (#7) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
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.

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 4:12 pm  (#8) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
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.


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 6:59 pm  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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().

_________________
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 7:17 pm  (#10) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
I think you should read the GIMP Python Documentation

_________________
https://www.deviantart.com/pocholo17
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Mon Oct 04, 2021 7:49 pm  (#11) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
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.


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Tue Oct 05, 2021 2:24 am  (#12) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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'>)

_________________
Image


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Tue Oct 05, 2021 2:54 pm  (#13) 
Offline
GimpChat Member

Joined: Oct 10, 2014
Posts: 36
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"!!!


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Tue Oct 05, 2021 3:59 pm  (#14) 
Offline
GimpChat Member
User avatar

Joined: Aug 08, 2016
Posts: 2061
Location: East Midlands of England
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.

_________________
Image

"Let no one steal your dreams."
Paul Cookson


Latest plug-in update: Paragrapher v.1.4
Custom Font Links
Tools
Character Paths
White Bases


Top
 Post subject: Re: Unable to export jpg after added a new layer
PostPosted: Wed Oct 06, 2021 6:50 am  (#15) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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?

_________________
Image


Top
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Unable to paint on transparent layer

1

No new posts Attachment(s) Unable to load an image as layer

16

No new posts Newly Added Brush Demos by SenlinOS

2

No new posts Attachment(s) David added Voronoi to the latest GMIC

27



* Login  



Powered by phpBB3 © phpBB Group