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])
| 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): |