Skip to content

Commit e4934e8

Browse files
author
Steve Canny
committed
img: wire up Png and Image initializers
1 parent a20f25b commit e4934e8

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

docx/image/image.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class Image(object):
1717
Graphical image stream such as JPEG, PNG, or GIF with properties and
1818
methods required by ImagePart.
1919
"""
20+
def __init__(self, blob, filename, px_width, px_height, attrs):
21+
super(Image, self).__init__()
22+
self._blob = blob
23+
self._filename = filename
24+
self._px_width = px_width
25+
self._px_height = px_height
26+
self._attrs = attrs
27+
2028
@classmethod
2129
def from_file(cls, image_descriptor):
2230
"""

docx/image/png.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class Png(Image):
1717
"""
1818
Image header parser for PNG images
1919
"""
20+
def __init__(self, blob, filename, cx, cy, attrs):
21+
super(Png, self).__init__(blob, filename, cx, cy, attrs)
22+
2023
@classmethod
2124
def from_stream(cls, stream, blob, filename):
2225
"""
@@ -79,13 +82,15 @@ def _parse_chunks(cls, stream, chunk_offsets):
7982
"""
8083
attrs = {}
8184

85+
# IHDR chunk -------------------
8286
if _CHUNK_TYPE_IHDR not in chunk_offsets:
8387
# IHDR chunk is mandatory, invalid if not present
8488
raise InvalidImageStreamError('no IHDR chunk in PNG image')
8589
ihdr_offset = chunk_offsets[_CHUNK_TYPE_IHDR]
8690
ihdr_attrs = cls._parse_IHDR(stream, ihdr_offset)
8791
attrs.update(ihdr_attrs)
8892

93+
# pHYs chunk -------------------
8994
if _CHUNK_TYPE_pHYs in chunk_offsets:
9095
phys_offset = chunk_offsets[_CHUNK_TYPE_pHYs]
9196
phys_attrs = cls._parse_pHYs(stream, phys_offset)

0 commit comments

Comments
 (0)