[Tutor] From byte[] to Image

Ziad Rahhal ziad.rahhal at gmail.com
Mon Sep 18 11:59:09 CEST 2006


I do the following:

file = StringIO.StringIO(buffer)
img = Image.open(file)
img.save(file, 'JPEG')

I get this error:
img = Image.open(file)
  File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line
1745, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

Yes I printed the contents of Buffer but how can I make sure if it is all
there since the type I am receiving is
different (temporarly, until I form the Image) from the original content of
the Image itself. I will attach the buffer
I am receiving and the original Image I am sending.


On 9/17/06, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
>
> > (Note that this function decodes pixel data only, not entire images.
> > If you
> > have an entire image file in a string, wrap it in a *StringIO*
> > object, and
> > use
> > *open*<file:///home/rahhal/Imaging-1.1.5/Docs/pythondoc-PIL.Image.html#PIL.Image.open-function
> >to
> > load it.)
> >
> > So I guess "frombuffer" must not be used in my case.
>
> Looks like it, but did you try what it suggested, namely using
> a StringIO object and the open method?
>
> What happened?
>
> > The java method is working correctly but I am not able to form the
> > picture
> > in the right way at the client side using the PIL library.
>
> > I receive it at the client side in python:
> > buffer = service.getFile(fileName)
>
> I assume you tried printing buffer (or at least its len) to check that
> it was all there?
>
> Alan G.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060918/142981dc/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: buffer
Type: application/octet-stream
Size: 11332 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060918/142981dc/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.jpg
Type: image/jpeg
Size: 27798 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060918/142981dc/attachment-0001.jpg 


More information about the Tutor mailing list