[Image-SIG] frombuffer defaults to flip of fromstring?

Dan Torop dtorop933 at gmail.com
Thu Jul 6 21:37:03 CEST 2006

I was curious whether there was a bug in the default behavior of
Image.frombuffer().  Consider the example:

import Image
out = '\xff\x00\x00\xff\xff\x00\xff\xff\xff'
Image.fromstring('L', (3, 3), out).save('string-default.png')
Image.frombuffer('L', (3, 3), out).save('buffer-default.png')
Image.frombuffer('L', (3, 3), out, 'raw', 'L', 0,

Running against PIL 1.1.5 I see "buffer-default.png" is upside down
compared to "string-default.png".  OTOH, "buffer-oriented-1.png"
(where the orientation is manually set to 1) matches

The online documentation
(http://www.pythonware.com/library/pil/handbook/decoder.htm#h0003) it
says re orientation: "Whether the first line in the image is the top
line on the screen (1), or the bottom line (-1). If omitted, the
orientation defaults to 1." So actual behavior seems to be contrary to
both expected and documented behavior.

Assuming this is a real problem, a fix to frombuffer (vs. 1.1.6b1) might be:

--- Imaging-1.1.6b1/PIL/Image.py.orig   2006-07-06 15:23:16.000000000 -0400
+++ Imaging-1.1.6b1/PIL/Image.py        2006-07-06 15:23:35.000000000 -0400
@@ -1738,7 +1738,7 @@

     if decoder_name == "raw":
         if args == ():
-            args = mode, 0, -1
+            args = mode, 0, 1
         if args[0] in _MAPMODES:
             im = new(mode, (1,1))
             im = im._new(

Sorry to make a fuss about this if there is a rationale for the
difference between fromstring() and frombuffer().

Thanks very much,


More information about the Image-SIG mailing list