Is '.seller' a GIF or a JPEG?
Why the somewhat unusual file-naming convention?
> img.convert('RGB')
> img.save('.seller', 'BMP')
Have you tried not saving it with the same name?
> But unfortuantly that doesnt work:
> Exception("bitmap isn't a 24bit true color bitmap.")
>
> Can anyone help me out?
>
> PS: According to PIL documentation (http://www.pythonware.com/library/
> pil/handbook/concepts.htm) RGB = (3x8-bit pixels, true colour)
It works for me (in my environment, on 1 sample JPEG file); details:
foo.jpg: copy of Water Lilies.jpg found in .../My Pictures/Samples/...
or some such folder
PIL: freshly installed from
http://effbot.org/downloads/PIL-1.1.6.win32-py2.6.exe
xlwt: 0.7.1
C:\xlwt\images>\python26\python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> img = Image.open('foo.jpg')
>>> img.convert('RGB')
<PIL.Image.Image instance at 0x00F6A058>
>>> img.save('bar', 'BMP')
>>> ^Z
'bar' is reported by various image programs as being a 24 bits-per-pixel
BMP file.
C:\xlwt\images>\python26\python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
>>> wb = xlwt.Workbook()
>>> ws = wb.add_sheet("image")
>>> ws.insert_bitmap('bar', 2, 2)
>>> wb.save('bmp_from_jpg.xls')
>>> ^Z
Excel 2003 opens the file OK and the picture looks fine.
C:\xlwt\images>type dump_bmp_header.py
# dump BMP header
import struct, sys
fname = sys.argv[1]
data = open(fname, 'rb').read()
guff = struct.unpack("<2s6L2H", data[:30])
fmt = ("sig=%r, bitmap_size=%r, reserved1=%r, offset=%r,\n"
"header_len=%r, width=%r, height=%r, planes=%r, bit_count=%r")
print fmt % guff
C:\xlwt\images>dump_bmp_header.py python.bmp
sig='BM', bitmap_size=37446, reserved1=0, offset=54,
header_len=40, width=76, height=164, planes=1, bit_count=24
C:\xlwt\images>dump_bmp_header.py bar
sig='BM', bitmap_size=1440054, reserved1=0, offset=54,
header_len=40, width=800, height=600, planes=1, bit_count=24
Note that the code in Bitmap.py raises the exception that you saw if
bit_count != 24. It has already checked that sig == "BM". The next thing
that it will check is that planes == 1. Evidently planes are called
"frames" by some software. There's a possibility that your file may have
3 x 8 instead of 1 x 24.
Please tell us what your environment is.
Please run the dump_bmp_header.py on your file.
Can you send a copy of your original GIF/JPEG file?
Cheers,
John
I don't know how you got 8 in there ....
C:\xlwt\images>\python26\python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> img = Image.open('oifzfp.jpg')
>>> img.convert('RGB')
<PIL.Image.Image instance at 0x00F8F2D8>
>>> img.save('oifzfp_conv.bmp', 'BMP')
>>> ^Z
C:\xlwt\images>dump_bmp_header.py oifzfp_conv.bmp
sig='BM', bitmap_size=14454, reserved1=0, offset=54,
header_len=40, width=160, height=30, planes=1, bit_count=24
*AND* I got the same effect when I left out the img.convert('RGB') step
... the JPEG file is already RGB.
So: I suggest that you either
(a) find another method of converting files to BMP format
or
(b) stick with PIL, gird up your loins, and do battle with the effbot :-)
Cheers,
John
Already got that info (spread over two messages).
Very strange. As I reported last time, omitting the convert step made no
difference.
C:\xlwt\images>\python26\python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> img = Image.open('oifzfp.jpg')
>>> img.bits
8
>>> img.format
'JPEG'
>>> img.info
{'jfif_version': (1, 1), 'jfif': 257, 'jfif_unit': 2, 'jfif_density':
(0, 0)}
>>> img.mode
'RGB'
>>> img.save('.oifzfp_noconv_noext', 'BMP')
>>> ^Z
C:\xlwt\images>dump_bmp_header.py .oifzfp_noconv_noext
sig='BM', bitmap_size=14454, reserved1=0, offset=54,
header_len=40, width=160, height=30, planes=1, bit_count=24
==== see? no conversion step at all, got bit_count == 24
I can't get it to do bit_count = 8 at all. Did you post the wrong file
(oifzfp.jpg)?
In any case, any vague fears that xlwt was part of the problem seem to
have been well and truly dispelled.
Cheers,
John