MCPcopy Create free account
hub / github.com/scanny/python-pptx / get_or_add_image_part

Method get_or_add_image_part

src/pptx/package.py:146–155  ·  view source on GitHub ↗

Return |ImagePart| object containing the image in `image_file`. `image_file` can be either a path to an image file or a file-like object containing an image. If an image part containing this same image already exists, that instance is returned, otherwise a new image part is

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

Source from the content-addressed store, hash-verified

144 yield image_part
145
146 def get_or_add_image_part(self, image_file: str | IO[bytes]) -> ImagePart:
147 """Return |ImagePart| object containing the image in `image_file`.
148
149 `image_file` can be either a path to an image file or a file-like object
150 containing an image. If an image part containing this same image already exists,
151 that instance is returned, otherwise a new image part is created.
152 """
153 image = Image.from_file(image_file)
154 image_part = self._find_by_sha1(image.sha1)
155 return image_part if image_part else ImagePart.new(self._package, image)
156
157 def _find_by_sha1(self, sha1: str) -> ImagePart | None:
158 """

Callers

nothing calls this directly

Calls 3

_find_by_sha1Method · 0.95
from_fileMethod · 0.80
newMethod · 0.45

Tested by

no test coverage detected