[Image-SIG] PIL Image.load() doesn't return pixel array

Fredrik Lundh fredrik at pythonware.com
Mon Mar 3 22:25:24 CET 2008

Christopher Brooks wrote:

> I've been using PIL a fair bit lately and am really liking it - it's great
> to have such a library available.  The docs suggest that im.load() should
> return a pixel access object, but this doesn't actually seem to always work.
> Sometimes I get the object, sometimes I get a None back.
> In particular, it seems when I take an image, run a crop() on it, then a
> load() on it, I'll tend to get the None back.  I can probably drum up an
> example of this if it is useful, but I'm wondering if there are any caveats
> of the load() method that are not listed in the docs?

it's a known bug in the "lazy crop" class.  here's a patch:

Index: PIL/Image.py
--- PIL/Image.py        (revision 3324)
+++ PIL/Image.py        (revision 3325)
@@ -1645,6 +1645,9 @@
              self.im = self.im.crop(self.__crop)
              self.__crop = None

+        if self.im:
+            return self.im.pixel_access(self.readonly)
          # FIXME: future versions should optimize crop/paste
          # sequences!


More information about the Image-SIG mailing list