[Zope] PIL: can't call same method twice
Tino Wildenhain
tino at wildenhain.de
Sun Mar 6 11:38:51 EST 2005
Am Sonntag, den 06.03.2005, 14:28 +0100 schrieb Chris:
> Hi Dieter,
>
> > Almost surely, your first call moved the file pointer to
> > the end and the second one does not find content.
> >
> > You can use the "seek" method to reposition the file pointer.
>
> That is, what I thought, too. So I added in PIL.Image.py (Version 1.1.4)
> in line 1548 "fp.seek(0)" to "rewind" the file object (see below) to no
> avail. So I guess I am not in the right place. But I will dig into the
> PIL code soon.
> Thanx for pointing me in the right direction.
> Regards Chris
You dont have to change PIL code. Just use Parser instead
of the Image object directly.
import PIL.ImageFile
parser=PIL.ImageFile.Parser()
chunksize=8192
yourfile.seek(0)
chunk=yourfile.read(chunksize)
while chunk:
parser.feed(chunk)
chunk=yourfile.read(chunksize)
img=parser.close()
...
after the first chunk you feed in, parser.image can contain
data of your image, so you can read width and height
More information about the Zope
mailing list