It is currently Sat Jul 06, 2024 7:47 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Width of a image
PostPosted: Mon Dec 05, 2016 6:35 pm  (#1) 
Offline
GimpChat Member

Joined: Nov 08, 2016
Posts: 45
Looking at various examples of python-fu, it seems the width of an image can be obtained with method #1 or method #2 below (see below). Method #2 is a property of the image object. Where are the properties documented or how can I see all the properties of the image? Is one method preferred over the other?

>>> img=gimp.image_list()[0]
>>> # Method 1
>>> gimp.pdb.gimp_image_width(img)
640
>>> # Method 2
>>> img.width
640


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: Width of a image
PostPosted: Mon Dec 05, 2016 7:30 pm  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4003
Location: Canada
I just prefer method 2.

I don't know where documentation is for image's attributes and methods are
but using the below code it prints out all the methods and attributes for image
   methods = []
   for method in dir(image):
      if hasattr(image, method):
         methods.append(method)
   pdb.gimp_message(str(methods))

it prints out this list
['ID', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'active_channel', 'active_drawable', 'active_layer', 'active_vectors', 'add_channel', 'add_hguide', 'add_layer', 'add_vguide', 'attach_new_parasite', 'base_type', 'channels', 'clean_all', 'crop', 'delete_guide', 'dirty', 'disable_undo', 'duplicate', 'enable_undo', 'filename', 'find_next_guide', 'flatten', 'floating_sel_attached_to', 'floating_selection', 'free_shadow', 'get_channel_by_tattoo', 'get_component_active', 'get_component_visible', 'get_guide_orientation', 'get_guide_position', 'get_layer_by_tattoo', 'height', 'insert_channel', 'insert_layer', 'layers', 'lower_channel', 'lower_layer', 'lower_layer_to_bottom', 'merge_down', 'merge_visible_layers', 'name', 'new_layer', 'parasite_attach', 'parasite_detach', 'parasite_find', 'parasite_list', 'pick_correlate_layer', 'raise_channel', 'raise_layer', 'raise_layer_to_top', 'remove_channel', 'remove_layer', 'resize', 'resize_to_layers', 'resolution', 'scale', 'selection', 'set_component_active', 'set_component_visible', 'tattoo_state', 'undo_freeze', 'undo_group_end', 'undo_group_start', 'undo_is_enabled', 'undo_thaw', 'unit', 'unset_active_channel', 'uri', 'vectors', 'width']

Some are methods, i guess you'll just to play around with them to get the right parameters going.
or a link to documentation would be nice usually, the methods need parameters just like their pdb.methods equivalent without the image parameter since this already belongs to image.

_________________
TinT


Top
 Post subject: Re: Width of a image
PostPosted: Tue Dec 06, 2016 3:27 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
In the python console
dir(image)

does the same. In practice you'll also find other objects/classes with other not-too-documented attributes. Some are read-only, some can be written to (layer.name='New name'). Instinct, experimentation and comparison with the pdb.* method usually gives you enough to work them out.

Using the object methods/attributes makes for more readable (and oftesn simpler) code.

_________________
Image


Top
 Post subject: Re: Width of a image
PostPosted: Tue Dec 06, 2016 10:06 am  (#4) 
Offline
GimpChat Member

Joined: Nov 08, 2016
Posts: 45
Very helpful!

With the dir(image) example, image is really something like:

dir(gimp.image_list()[0])


The only way I know how to get access to the image is

images = gimp.image_list()
image = images[0]



I found additional help in the Python Console:
import gimpfu
help(gimpfu)


Top
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Show image on web browser to fill 100% width AND image map

2

No new posts Retexture an image with another image as "Image Pattern" Plug-in

4

No new posts Attachment(s) image name

2

No new posts Attachment(s) Image Logo

3

No new posts Attachment(s) Cropping an image

6



* Login  



Powered by phpBB3 © phpBB Group