MCPcopy Index your code
hub / github.com/python-openxml/python-docx / add_picture

Method add_picture

src/docx/document.py:121–138  ·  view source on GitHub ↗

Return new picture shape added in its own paragraph at end of the document. The picture contains the image at `image_path_or_stream`, scaled based on `width` and `height`. If neither width nor height is specified, the picture appears at its native size. If only one is specif

(
        self,
        image_path_or_stream: str | IO[bytes],
        width: int | Length | None = None,
        height: int | Length | None = None,
    )

Source from the content-addressed store, hash-verified

119 return self._body.add_paragraph(text, style)
120
121 def add_picture(
122 self,
123 image_path_or_stream: str | IO[bytes],
124 width: int | Length | None = None,
125 height: int | Length | None = None,
126 ):
127 """Return new picture shape added in its own paragraph at end of the document.
128
129 The picture contains the image at `image_path_or_stream`, scaled based on
130 `width` and `height`. If neither width nor height is specified, the picture
131 appears at its native size. If only one is specified, it is used to compute a
132 scaling factor that is then applied to the unspecified dimension, preserving the
133 aspect ratio of the image. The native size of the picture is calculated using
134 the dots-per-inch (dpi) value specified in the image file, defaulting to 72 dpi
135 if no value is specified, as is often the case.
136 """
137 run = self.add_paragraph().add_run()
138 return run.add_picture(image_path_or_stream, width, height)
139
140 def add_section(self, start_type: WD_SECTION = WD_SECTION.NEW_PAGE):
141 """Return a |Section| object newly added at the end of the document.

Callers

nothing calls this directly

Calls 2

add_paragraphMethod · 0.95
add_runMethod · 0.80

Tested by

no test coverage detected