Skip to content

Commit d5dd051

Browse files
Benjamin-TBenjamin-T
authored andcommitted
added style argument to the add_picture method, the pictures can now be centered
1 parent cab6ecd commit d5dd051

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

docx/document.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def add_caption(self, caption, bmark, obj_type='figure'):
213213
self.create_caption(caption, par, obj_type, bmark)
214214
return par
215215

216-
def add_picture(self, image_path_or_stream, width=None, height=None):
216+
def add_picture(self, image_path_or_stream, width=None, height=None, style=None):
217217
"""
218218
Return a new picture shape added in its own paragraph at the end of
219219
the document. The picture contains the image at
@@ -226,7 +226,10 @@ def add_picture(self, image_path_or_stream, width=None, height=None):
226226
in the image file, defaulting to 72 dpi if no value is specified, as
227227
is often the case.
228228
"""
229-
run = self.add_paragraph().add_run()
229+
if style is not None:
230+
run = self.add_paragraph(style=style).add_run()
231+
else:
232+
run = self.add_paragraph().add_run()
230233
return run.add_picture(image_path_or_stream, width, height)
231234

232235
def add_section(self, start_type=WD_SECTION.NEW_PAGE):

0 commit comments

Comments
 (0)