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

Method get_or_add_image

src/docx/parts/story.py:27–39  ·  view source on GitHub ↗

Return (rId, image) pair for image identified by `image_descriptor`. `rId` is the str key (often like "rId7") for the relationship between this story part and the image part, reused if already present, newly created if not. `image` is an |Image| instance providing access to

(self, image_descriptor: str | IO[bytes])

Source from the content-addressed store, hash-verified

25 """
26
27 def get_or_add_image(self, image_descriptor: str | IO[bytes]) -> Tuple[str, Image]:
28 """Return (rId, image) pair for image identified by `image_descriptor`.
29
30 `rId` is the str key (often like "rId7") for the relationship between this story
31 part and the image part, reused if already present, newly created if not.
32 `image` is an |Image| instance providing access to the properties of the image,
33 such as dimensions and image type.
34 """
35 package = self._package
36 assert package is not None
37 image_part = package.get_or_add_image_part(image_descriptor)
38 rId = self.relate_to(image_part, RT.IMAGE)
39 return rId, image_part.image
40
41 def get_style(self, style_id: str | None, style_type: WD_STYLE_TYPE) -> BaseStyle:
42 """Return the style in this document matching `style_id`.

Callers 2

new_pic_inlineMethod · 0.95

Calls 2

get_or_add_image_partMethod · 0.45
relate_toMethod · 0.45

Tested by 1