PIL: reading bytes from Image

Max Erickson maxerickson at gmail.com
Sun Mar 11 12:37:26 EDT 2007


"cyberco" <cyberco at gmail.com> wrote:

> Thanks,
> 
> I've tried the StringIO option as follows:
> 
> =================================
> img = Image.open('/some/path/img.jpg')
> img.thumbnail((640,480))
> file = StringIO, StringIO()

Is the above line exactly what you tried? If it is, the comma and 
space in the line are likely the problem. Try either:

from StringIO import StringIO 
file=StringIO()

or

import StringIO
file=StringIO.StringIO()

(using file as a variable name can cause issues if you later want 
access to the built in object 'file')

The following:

>>> import Image
>>> import StringIO
>>> im=Image.new('RGB', (100,100))
>>> fp=StringIO.StringIO()
>>> im.save(fp, 'jpeg')
>>> len(fp.getvalue())
823

Works for me on python 2.5 on windows.


max




More information about the Python-list mailing list