read part of jpeg file by pure python

Pacino xiaoyisheng at
Thu Sep 13 10:48:45 CEST 2007

On 9 13 ,   4 43 , Laurent Pointal <laurent.poin... at> wrote:
> Pacino a écrit :
> > Hi, everyone,
> > I am wondering whether it's possible to read part (e.g. 1000*1000) of
> > a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file
> > by pure python. I failed to read the whole file and split it, because
> > it would cost 2GB memory.
> > Can anyone help me? Any comments would be appreciated.
> > Thanks.
> > Robert
> Just reading parts of the *file* is easy (see tell() seek() and read()
> methods on files).
> But to extract a part of the *picture*, you must uncompress the picture
> in memory, grab the sub-picture, and save it back - generally with
> compression. I can't see how you can bypass the uncompress/compress
> phases and the corresponding memory use.
> A+
> Laurent.

The most difficult part is the uncompress part. I don't want the whole
picture to be uncompressed in the memory, because it will consume a
lot of memory (2GB, as I mentioned). My goal is to uncompress part of
the picture into the memory.

I just read some article on this subject (
pipermail/image-sig/1999-April/000713.html) , but haven't test it out


More information about the Python-list mailing list