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

Method from_file

src/docx/image/image.py:36–50  ·  view source on GitHub ↗

Return a new |Image| subclass instance loaded from the image file identified by `image_descriptor`, a path or file-like object.

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

Source from the content-addressed store, hash-verified

34
35 @classmethod
36 def from_file(cls, image_descriptor: str | IO[bytes]):
37 """Return a new |Image| subclass instance loaded from the image file identified
38 by `image_descriptor`, a path or file-like object."""
39 if isinstance(image_descriptor, str):
40 path = image_descriptor
41 with open(path, "rb") as f:
42 blob = f.read()
43 stream = io.BytesIO(blob)
44 filename = os.path.basename(path)
45 else:
46 stream = image_descriptor
47 stream.seek(0)
48 blob = stream.read()
49 filename = None
50 return cls._from_stream(stream, blob, filename)
51
52 @property
53 def blob(self):

Calls 3

readMethod · 0.80
seekMethod · 0.80
_from_streamMethod · 0.80