Return |ImagePart| object containing image identified by `image_descriptor`. The image-part is newly created if a matching one is not present in the collection.
(self, image_descriptor: str | IO[bytes])
| 66 | self._image_parts.append(item) |
| 67 | |
| 68 | def get_or_add_image_part(self, image_descriptor: str | IO[bytes]) -> ImagePart: |
| 69 | """Return |ImagePart| object containing image identified by `image_descriptor`. |
| 70 | |
| 71 | The image-part is newly created if a matching one is not present in the |
| 72 | collection. |
| 73 | """ |
| 74 | image = Image.from_file(image_descriptor) |
| 75 | matching_image_part = self._get_by_sha1(image.sha1) |
| 76 | if matching_image_part is not None: |
| 77 | return matching_image_part |
| 78 | return self._add_image_part(image) |
| 79 | |
| 80 | def _add_image_part(self, image: Image): |
| 81 | """Return |ImagePart| instance newly created from `image` and appended to the collection.""" |