[PYTHON IMAGE-SIG] Basic PIL problems

Ralph Heinkel Ralph.Heinkel@embl-heidelberg.de
Wed, 5 Mar 1997 14:44:46 GMT


Hello,

I just got PIL installed (version 0.2b4), but basically I cannot do
very much (or I misunderstood almost everything).

First try: Using pilfile.py

hobbes:/struct/fuller1/heinkel/src/Python-1.4/Extensions/Imaging$ python pilfile.py Images/lena.gif
Image: failed to import ArgImagePlugin : cannot import name ChunkStream
Traceback (innermost last):
  File "pilfile.py", line 60, in ?
    im = Image.open(file)
  File "/usr/local/lib/python1.4/Image.py", line 401, in open
    init()
  File "/usr/local/lib/python1.4/Image.py", line 74, in init
    exec "import " + f
  File "<string>", line 1, in ?
  File "/usr/local/lib/python1.4/WmfImagePlugin.py", line 274, in ?
    Image.register_open("WMF", WmfImageFile, _accept)
TypeError: too many arguments
hobbes:/struct/fuller1/heinkel/src/Python-1.4/Extensions/Imaging


Second try: Using pilconvert.py

hobbes:/struct/fuller1/heinkel/src/Python-1.4/Extensions/Imaging$ python pilconvert.py Images/lena.gif Images/lena.tif
Image: failed to import ArgImagePlugin : cannot import name ChunkStream
cannot convert image (TypeError:too many arguments)
hobbes:/struct/fuller1/heinkel/src/Python-1.4/Extensions/Imaging$


Third try: Doing things manually in python

Why does it work to open the file, when I do it two times in a row?

hobbes:/trash/heinkel/python$ python
Python 1.4 (Nov 12 1996)  [GCC 2.7.2.f.1]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import Image
>>> im=Image.open('lena.gif')
Image: failed to import ArgImagePlugin : cannot import name ChunkStream
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python1.4/Image.py", line 401, in open
    init()
  File "/usr/local/lib/python1.4/Image.py", line 74, in init
    exec "import " + f
  File "<string>", line 1, in ?
  File "/usr/local/lib/python1.4/WmfImagePlugin.py", line 274, in ?
    Image.register_open("WMF", WmfImageFile, _accept)
TypeError: too many arguments
>>> im=Image.open('lena.gif')
>>> 


In Image.py I found the methods 'tostring' and 'fromstring' which
are not documented (at least not in my 0.2B3 docu). Does the format
of the returned/accepted string depend on the image format, or is
it an independent internal format? 

What I would like to do is:
I have a string 'myimage' received from a selfmade python module
which holds a 100x100 grayscale image, with 2 bytes/pixel. How
can I feed that into PIL to get a tif/gif/ppm file? Is 'fromstring'
the right way to do that? 

A first try using 'tostring' and 'fromstring' failed:

>>> im=Image.open('lena.gif')
>>> im.mode
'P'
>>> im.format
'GIF'
>>> im2=Image.new(im.mode,im.size)  # create new file, same mode and size
>>> im2.fromstring(im.tostring())   # copy image ...
>>> im2.save('lena2.gif')           # and save it
sh: ppmtogif: command not found
>>>

Does that imply that 'tostring' returns an image in ppm format?
Can't PIL do the reverse thing internally?

Questions about questions ...
I hope that anybody can help me with that.

Thanks,

Ralph


_______________
IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
_______________