Skip to content

Commit 87460cc

Browse files
author
Steve Canny
committed
img: add BMP format to recognizer
1 parent 23ef66e commit 87460cc

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

docx/image/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from docx.compat import BytesIO, is_string
2121
from docx.exceptions import UnrecognizedImageError
22+
from docx.image.bmp import Bmp
2223
from docx.image.gif import Gif
2324
from docx.image.jpeg import Exif, Jfif
2425
from docx.image.png import Png
@@ -36,6 +37,7 @@
3637
(Gif, 0, b'GIF89a'),
3738
(Tiff, 0, b'MM\x00*'), # big-endian (Motorola) TIFF
3839
(Tiff, 0, b'II*\x00'), # little-endian (Intel) TIFF
40+
(Bmp, 0, b'BM'),
3941
)
4042

4143

docx/image/bmp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# encoding: utf-8
2+
3+
4+
class Bmp(object):
5+
"""
6+
Image header parser for BMP images
7+
"""

tests/image/test_image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from docx.compat import BytesIO
1212
from docx.exceptions import UnrecognizedImageError
1313
from docx.image import image_cls_that_can_parse, Image_OLD
14+
from docx.image.bmp import Bmp
1415
from docx.image.gif import Gif
1516
from docx.image.image import Image
1617
from docx.image.jpeg import Exif, Jfif
@@ -45,6 +46,7 @@ def it_raises_on_unrecognized_image_stream(self):
4546
('sonic.gif', Gif),
4647
('72-dpi.tiff', Tiff),
4748
('little-endian.tif', Tiff),
49+
('python.bmp', Bmp),
4850
])
4951
def image_cls_lookup_fixture(self, request):
5052
image_filename, expected_class = request.param

0 commit comments

Comments
 (0)