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

Method add_picture

src/docx/text/run.py:59–81  ·  view source on GitHub ↗

Return |InlineShape| containing image identified by `image_path_or_stream`. The picture is added to the end of this run. `image_path_or_stream` can be a path (a string) or a file-like object containing a binary image. If neither width nor height is specified, the p

(
        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

57 br.clear = clear
58
59 def add_picture(
60 self,
61 image_path_or_stream: str | IO[bytes],
62 width: int | Length | None = None,
63 height: int | Length | None = None,
64 ) -> InlineShape:
65 """Return |InlineShape| containing image identified by `image_path_or_stream`.
66
67 The picture is added to the end of this run.
68
69 `image_path_or_stream` can be a path (a string) or a file-like object containing
70 a binary image.
71
72 If neither width nor height is specified, the picture appears at
73 its native size. If only one is specified, it is used to compute a scaling
74 factor that is then applied to the unspecified dimension, preserving the aspect
75 ratio of the image. The native size of the picture is calculated using the dots-
76 per-inch (dpi) value specified in the image file, defaulting to 72 dpi if no
77 value is specified, as is often the case.
78 """
79 inline = self.part.new_pic_inline(image_path_or_stream, width, height)
80 self._r.add_drawing(inline)
81 return InlineShape(inline)
82
83 def add_tab(self) -> None:
84 """Add a ``<w:tab/>`` element at the end of the run, which Word interprets as a

Calls 3

InlineShapeClass · 0.90
add_drawingMethod · 0.80
new_pic_inlineMethod · 0.45

Tested by 2

it_can_add_a_pictureMethod · 0.76
it_can_add_a_pictureMethod · 0.36