views:

43

answers:

1

Hey guys, I have a png file generated by Gnuplot that I need to put into an excel document using XLWT.

XLWT can't import PNG's into the document, only BMP's, so I needed to convert the PNG first. I used PIL for this.

Here's the relevant code:

im = Image.open('%s' % os.path.join(os.getcwd(), s + '.png'))
im.save('%s.bmp' % s)

However XLWT gives me this error:

Exception: bitmap isn't a 24bit true color bitmap.

Here's what the XLWT code looks like:

self.chart.insert_bitmap(path, 2, 2) 

I know both images work fine, they're both openable by windows. I've also tried adding a 2 second pause after creating the BMP (to make up for write time), but it still fails.

How do I go about making a 24 bit true color bitmap using PIL?

+1  A: 

Nevermind! Just figured it out myself.

Change

im = Image.open('%s' % os.path.join(os.getcwd(), s + '.png'))

To

im = Image.open('%s' % os.path.join(os.getcwd(), s + '.png')).convert("RGB")
Alpaca