Skip to content

Commit 4434b1c

Browse files
author
Steve Canny
committed
img: add GIF formats to recognizer
1 parent 98f3f24 commit 4434b1c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

docx/image/__init__.py

Lines changed: 3 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.gif import Gif
2223
from docx.image.jpeg import Exif, Jfif
2324
from docx.image.png import Png
2425
from docx.opc.constants import CONTENT_TYPE as CT
@@ -30,6 +31,8 @@
3031
(Png, 0, b'\x89PNG\x0D\x0A\x1A\x0A'),
3132
(Jfif, 6, b'JFIF'),
3233
(Exif, 6, b'Exif'),
34+
(Gif, 0, b'GIF87a'),
35+
(Gif, 0, b'GIF89a'),
3336
)
3437

3538

docx/image/gif.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# encoding: utf-8
2+
3+
from __future__ import absolute_import, division, print_function
4+
5+
from .image import Image
6+
7+
8+
class Gif(Image):
9+
"""
10+
Image header parser for GIF images. Note that the GIF format does not
11+
support resolution (DPI) information. Both horizontal and vertical DPI
12+
default to 72.
13+
"""

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.gif import Gif
1415
from docx.image.image import Image
1516
from docx.image.jpeg import Exif, Jfif
1617
from docx.image.png import Png
@@ -40,6 +41,7 @@ def it_raises_on_unrecognized_image_stream(self):
4041
('python-icon.png', Png),
4142
('python-icon.jpeg', Jfif),
4243
('exif-420-dpi.jpg', Exif),
44+
('sonic.gif', Gif),
4345
])
4446
def image_cls_lookup_fixture(self, request):
4547
image_filename, expected_class = request.param

0 commit comments

Comments
 (0)