python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.08k stars 2.21k forks source link

Unable to open bitmapv5 format BMP image file #239

Closed ferozed closed 10 years ago

ferozed commented 11 years ago

I am trying to open a BMP image file. This file is valid and opens fine with eog (eye of gnome) on linux. It identifies correctly as well.

sh:~/home/user$ identify -verbose badbmp.bmp Image: badbmp.bmp Format: BMP (Microsoft Windows bitmap image) Class: DirectClass Geometry: 940x705+0+0 Units: PixelsPerCentimeter Type: TrueColorMatte Endianess: Undefined Colorspace: RGB Depth: 8-bit Channel depth: red: 8-bit green: 8-bit blue: 8-bit alpha: 1-bit Channel statistics: Red: min: 7 (0.027451) max: 255 (1) mean: 82.3111 (0.322788) standard deviation: 42.3517 (0.166085) kurtosis: 9.21784 skewness: 2.94025 Green: min: 7 (0.027451) max: 255 (1) mean: 80.6959 (0.316454) standard deviation: 43.208 (0.169443) kurtosis: 8.72161 skewness: 2.84078 Blue: min: 5 (0.0196078) max: 255 (1) mean: 76.912 (0.301616) standard deviation: 45.1296 (0.176979) kurtosis: 7.82117 skewness: 2.6619 Alpha: min: 255 (1) max: 255 (1) mean: 255 (1) standard deviation: 0 (0) kurtosis: 0 skewness: 0 Image statistics: Overall: min: 5 (0.0196078) max: 255 (1) mean: 123.73 (0.485215) standard deviation: 84.6884 (0.332111) kurtosis: -1.16829 skewness: 0.805031 Alpha: rgba(52,52,52,0) #34343400 Rendering intent: Undefined Chromaticity: red primary: (-nan,-nan) green primary: (-nan,-nan) blue primary: (-nan,-nan) white point: (0,0) Interlace: None Background color: white Border color: rgba(223,223,223,1) Matte color: grey74 Transparent color: none Compose: Over Page geometry: 940x705+0+0 Dispose: Undefined Iterations: 0 Compression: Undefined Orientation: Undefined Properties: date:create: 2013-05-29T13:41:17-07:00 date:modify: 2013-05-29T13:41:17-07:00 signature: 06a0f3720396f746fa94ee4918f3150c9bd4931ff21e9bed66d8202b4824e215 Artifacts: verbose: true Tainted: False Filesize: 2.651MB Number pixels: 663KB Pixels per second: 66.27MB User time: 0.010u Elapsed time: 0:01.010 Version: ImageMagick 6.6.0-4 2012-08-17 Q16 http://www.imagemagick.org

My code looks like this...

imageBytes = None with open(fileName, 'rb') as f: imageBytes = f.read()

rawImage = Image.open(StringIO.StringIO(imageBytes))

However, when I run this, I get the following error:

File "/home/user/init.py", line 149, in convert_file_adv rawImage = Image.open(StringIO.StringIO(imageBytes)) File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1965, in open return factory(fp, filename) File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 91, in init self._open() File "/usr/lib/python2.7/dist-packages/PIL/BmpImagePlugin.py", line 170, in _open self._bitmap(offset=offset) File "/usr/lib/python2.7/dist-packages/PIL/BmpImagePlugin.py", line 102, in _bitmap raise IOError("Unsupported BMP header type (%d)" % len(s))

IOError: Unsupported BMP header type (124)

Now, I know that this was a repro with PIL and not Pillow. However, when I look at the BmpImagePlugin.py file in the git repo for pillow, I notice that it also does not support this format.

This request is to add support for this image type.

ferozed commented 11 years ago

Here is the image. Since github does not allow attacing of BMP files, I renamed the extension to JPG. H owever, it is actually a BMP file. badbmp

wiredfool commented 11 years ago

So, first up, this is pure python and not calling out to a library. So there's nothing that we get for free here.

According to a unreliable source: http://en.wikipedia.org/wiki/BMP_file_format, there are a range of header types, determined by their size. We support sizes 12, 40, and 64, but not the undocumented 52 or 56, and not the later 108 (windows since 95/nt) and 124 (win 98/2000). There's colorspaces, gamma, and ICC profiles added here.

aclark4life commented 11 years ago

@botouser Can you send us a pull request to add this feature?