[Image-SIG] tostring raw/RGB bitmap problem

Joe Connellan joec@mill.co.uk
Fri, 06 Sep 2002 17:33:34 +0100


Hi John,
    You just reminded me to take another look at it, I've worked out that shake
writes "8" into the bit depth field of the header - meaning 8 per channel, pil
expects to see 24 and assumes 8 is an 8-bit palette-mapped image, and changes my
requested "RGB" to "P". As a quick test I hard coded 24 in as the bits in pils
bmp reader/writer and it loads in fine - though when I'm trying to resize it, it
gives me the following error.

Traceback (most recent call last):
  File "C:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__
    return apply(self.func, args)
  File "C:\dev\imageViewer\imageViewer.py", line 457, in loadCB
    self.loadImage(filename)
  File "C:\dev\imageViewer\imageViewer.py", line 351, in loadImage
    self.img[0] = self.img[0].resize((self.squareSize, self.squareSize))
  File "C:\Python22\PIL\Image.py", line 661, in resize
    self.load()
  File "C:\Python22\PIL\ImageFile.py", line 152, in load
    raise IOError, "image file is truncated, %d bytes left in buffer" % len(b)
IOError: image file is truncated, 1024 bytes left in buffer

I also get it when trying to save from the shell, eg
>>> im = Image.open('blah.bmp')
>>> im.save('test.bmp')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python22\PIL\Image.py", line 709, in save
    self.load()
  File "C:\Python22\PIL\ImageFile.py", line 152, in load
    raise IOError, "image file is truncated, %d bytes left in buffer" % len(b)
IOError: image file is truncated, 1024 bytes left in buffer

so, one step further but no joy yet.

Joe

John Lockwood wrote:

> Joe,
>
> I'm curious about this as well.
> Which file formats are you having trouble with, tiffs are sometimes a problem
> in older versions of shake.
> Are you sure that the shake fileout image is 8bit ?
> Do you get similar errors tying to read the same formats from other programs
> like photoshop or gimp?
>
> >
> >
> > Subject: [Image-SIG] tostring raw/RGB bitmap problem
> > Date: Wed, 04 Sep 2002 16:31:05 +0100
> > From: Joe Connellan <joec@mill.co.uk>
> > To: image-sig@python.org
> >
> > I'm able to read in some BMP images using the following code
> >
> > img = Image.open("blah.bmp")
> > img.tostring("raw", "RGB", 0, -1)
> >
> > but on some other images - written by a different application (Shake
> > from Nothing Real) I get the following error
> >
> > Exception in Tkinter callback
> > Traceback (most recent call last):
> >   File "C:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__
> >     return apply(self.func, args)
> >   File "C:\dev\imageViewer\imageViewer.py", line 392, in loadCB
> >     self.importClip(fileList)
> >   File "C:\dev\imageViewer\imageViewer.py", line 272, in importClip
> >     self.imgData.append(img.tostring("raw", "RGB", 0, -1))
> >   File "C:\Python22\PIL\Image.py", line 354, in tostring
> >     e = _getencoder(self.mode, encoder_name, args)
> >   File "C:\Python22\PIL\Image.py", line 257, in _getencoder
> >     return apply(encoder, (mode,) + args + extra)
> > SystemError: unknown raw mode
> >
> > how could it understand "RGB" as the raw mode for some bitmaps but not
> > others?
> >
> > Has anyone come accross this before? any ideas on how I go about fixing
> > it?
> >
> > Thanks
> >
> > Joe
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig