It is currently Thu Jul 23, 2026 7:08 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: What is the procedure name for "crop to contents"?
PostPosted: Fri Jun 21, 2019 11:21 am  (#1) 
Offline
New Member

Joined: Jun 21, 2019
Posts: 4
I'm trying to write a python-fu plugin to batch crop all layers to contents. According to the documentation in the Procedure Browser, plug-in-autocrop-layer takes (INT, IMAGE, DRAWABLE). If I put in 3 parameters it throws a TypeError: wrong number of parameters. If I put 2 parameters, (INT, layer) it throws a TypeError: wrong parameter type. Could you please give some pointers on what am I doing wrong? Following is the code:

def trim_layers(image, layer):
    trim_layer_group(image.layers)

def trim_layer_group(group):
     for layer in group:
        if pdb.gimp_item_is_group(layer):
            trim_layer_group(layer.layers)
        else:
            pdb.plug_in_autocrop_layer(0, layer)


Cheers!


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: What is the procedure name for "crop to contents"?
PostPosted: Fri Jun 21, 2019 11:36 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14831
Location: roma, italy
Ignore first parameter, not used for python plug-ins.
Just use image, drawable.

_________________
"Where am I ?"


Top
 Post subject: Re: What is the procedure name for "crop to contents"?
PostPosted: Fri Jun 21, 2019 1:04 pm  (#3) 
Offline
New Member

Joined: Jun 21, 2019
Posts: 4
Thanks.

Now I'm not sure what the parameters are. Which image? gimp_item_get_image(layer)? The Image object passed to the main() function? The layer?

I've tried several combinations and none of them work.


Top
 Post subject: Re: What is the procedure name for "crop to contents"?
PostPosted: Fri Jun 21, 2019 1:20 pm  (#4) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4510
Location: Canada
the image of the one you're try to crop of.
usually it's the called image passed in from running plug-in
and the layer is the drawable you're trying to crop as well.

image is the image that the layer belongs to that you're trying to crop.

from your code you have image.layer then you're calling another function that deals with image.layers.
so I would guess you'd want to pass in the image to that function as well and use that as your image parameter.

something like
def trim_layers(image):
    trim_layer_group(image, image.layers)

def trim_layer_group(image, group):
     for layer in group:
        if pdb.gimp_item_is_group(layer):
            trim_layer_group(image, layer.layers)
        else:
            pdb.plug_in_autocrop_layer(image, layer)

_________________
TinT


Top
 Post subject: Re: What is the procedure name for "crop to contents"?
PostPosted: Fri Jun 21, 2019 3:09 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
hrodgair wrote:
Thanks.

Now I'm not sure what the parameters are. Which image? gimp_item_get_image(layer)? The Image object passed to the main() function? The layer?

I've tried several combinations and none of them work.


If your registration parameters start with a PF_IMAGE and a PF_DRAWABLE, (so the plugin function is "somefunction(image,drawable, ....)" ) then when the plugin is called the current image and its active drawable (layer, mask or channel) are automatically set in the first argument to the function.

_________________
Image


Top
 Post subject: Re: What is the procedure name for "crop to contents"?
PostPosted: Sun Jun 23, 2019 2:06 am  (#6) 
Offline
New Member

Joined: Jun 21, 2019
Posts: 4
That I understand. But I'm iteratinig over all layers, to crop them, and I'm not sure what arguments I should pass to the autocrop function. Obviously I have to pass the layer, but is it the image or the drawable? In either case, what is the other argument, then?


Top
 Post subject: Re: What is the procedure name for "crop to contents"?
PostPosted: Sun Jun 23, 2019 2:54 am  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
If you iterate over all layers, the image argument is the same each time, and the second is each layer in turn:

for layer in image.layers:
    pdb.plug_in_autocrop_layer(image, layer)


Of course in that case you don't need to be passed a layer as part of the plugin arguments, just declare the PF_IMAGE argument and skip the PF_DRAWABLE.

_________________
Image


Last edited by ofnuts on Sun Jun 23, 2019 2:24 pm, edited 1 time in total.

Top
 Post subject: Re: What is the procedure name for "crop to contents"?
PostPosted: Sun Jun 23, 2019 6:22 am  (#8) 
Offline
New Member

Joined: Jun 21, 2019
Posts: 4
Great! Thanks a lot for your help.


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group