[Image-SIG] PIL Consuming All System Resources

Fredrik Lundh fredrik at pythonware.com
Sun May 30 16:26:48 CEST 2010


I spent about a decade working on libraries with paging, tiling, and
streaming processing architectures.  PIL's simple storage model is
pretty much a reaction against that.  It has worked reasonably well
this far :-)

However, note that for resizing and some color conversions, the draft
& thumbnail operations can do a bunch of tricks to avoid decoding
everything; e.g. im.thumbnail((200, 150), Image.ANTIALIAS) only uses
40 MB peak on my machine for that image, and you can use draft to
specify a maximum size you're interested in dealing with:

>>> im = Image.open("1291762-img016.jpg")
>>> im.draft("RGB", (1000, 1000))
<JpegImagePlugin.JpegImageFile image mode=RGB size=2550x3510 at 0xE18580>
>>> im
<JpegImagePlugin.JpegImageFile image mode=RGB size=2550x3510 at 0xE18580>

(note that this modifies the image in place, and can only be used
directly after open.  also note that it doesn't necessarily give you
exactly the mode or size you're asking for, and it also doesn't work
for all formats)

</F>

2010/5/30 Yury V. Zaytsev <yury at shurup.com>:
> Hi!
>
> On Sun, 2010-05-30 at 14:59 +0200, Fredrik Lundh wrote:
>> The file has mode=RGB size=20400x28079, so you'd need about 2291246400
>> bytes to load it all into memory at once, and twice that to do e.g.
>> color conversion (which creates a second image memory), so it's a bit
>> on the big side, at least for a 32-bit environment.
>
> I was just about to complain how suboptimal PIL is at loading images,
> but first tried to load this in eog (which actually did render the image
> after consuming an insane amount of 1.8 Gb memory) and then in Gimp that
> was no better :-)
>
> I am wondering whether there's a way of performing image
> transformations without temporarily decoding the whole image in
> memory...
>
> --
> Sincerely yours,
> Yury V. Zaytsev
>
>


More information about the Image-SIG mailing list