[Tutor] Saving an Image in a Given Format
Eric Walstad
eric at ericwalstad.com
Mon Mar 31 17:37:10 CEST 2008
Wayne Watson wrote:
> current_image ... convert() and
> save() must be methods in that class. The question is what class/module?
> PIL?
I don't know, but you could try the following from the python command
line, which might give you some hints:
dir(current_image)
current_image.foobarfizzbang
>>> import Image # PIL Image class
>>> im = Image.open('/path/to/foo.jpg')
>>> dir(im) # Gives you a list of the object's attribute names
['_Image__transformer', '__doc__', '__getattr__', '__init__',
'__module__', '_copy', '_dump', '_expand', '_getexif', '_makeself',
'_new', '_open', 'app', 'applist', 'bits', 'category', 'convert',
'copy', 'crop', 'decoderconfig', 'decodermaxblock', 'draft', 'filename',
'filter', 'format', 'format_description', 'fp', 'fromstring',
'getbands', 'getbbox', 'getcolors', 'getdata', 'getextrema', 'getim',
'getpalette', 'getpixel', 'getprojection', 'histogram', 'huffman_ac',
'huffman_dc', 'im', 'info', 'layer', 'layers', 'load', 'load_djpeg',
'load_end', 'load_prepare', 'mode', 'offset', 'palette', 'paste',
'point', 'putalpha', 'putdata', 'putpalette', 'putpixel',
'quantization', 'quantize', 'readonly', 'resize', 'rotate', 'save',
'seek', 'show', 'size', 'split', 'tell', 'thumbnail', 'tile',
'tobitmap', 'tostring', 'transform', 'transpose', 'verify']
The following error message tells me the object came from PIL.Image, a
good hint.
>>> im.just_throw_me_an_error
Traceback (most recent call last):
File "/home/ewalstad/var/tmp/<string>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 493, in
__getattr__
raise AttributeError(name)
AttributeError: just_throw_me_an_error
More information about the Tutor
mailing list