Replace an image in a slide. Args: slide (SlidePage): The slide containing the image. img_id (int): The ID of the image to replace. image_path (str): The path to the new image. Raises: ValueError: If the image path does not exist.
(slide: SlidePage, img_id: int, image_path: str)
| 281 | |
| 282 | |
| 283 | def replace_image(slide: SlidePage, img_id: int, image_path: str): |
| 284 | """ |
| 285 | Replace an image in a slide. |
| 286 | |
| 287 | Args: |
| 288 | slide (SlidePage): The slide containing the image. |
| 289 | img_id (int): The ID of the image to replace. |
| 290 | image_path (str): The path to the new image. |
| 291 | |
| 292 | Raises: |
| 293 | ValueError: If the image path does not exist. |
| 294 | """ |
| 295 | if not os.path.exists(image_path): |
| 296 | raise ValueError( |
| 297 | f"The image {image_path} does not exist, consider use del_image if image_path in the given command is faked" |
| 298 | ) |
| 299 | shape = element_index(slide, img_id) |
| 300 | assert isinstance(shape, Picture), "The element is not a Picture." |
| 301 | img_size = PIL.Image.open(image_path).size |
| 302 | r = min(shape.width / img_size[0], shape.height / img_size[1]) |
| 303 | new_width = int(img_size[0] * r) |
| 304 | new_height = int(img_size[1] * r) |
| 305 | shape.width = Pt(new_width) |
| 306 | shape.height = Pt(new_height) |
| 307 | shape.img_path = image_path |
| 308 | |
| 309 | |
| 310 | def clone_paragraph(slide: SlidePage, div_id: int, paragraph_id: int): |
nothing calls this directly
no test coverage detected