MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / from_shape

Method from_shape

utils/src/presentation.py:480–519  ·  view source on GitHub ↗
(
        cls,
        slide_idx: int,
        shape_idx: int,
        shape: PPTXPicture,
        style: dict,
        text_frame: TextFrame,
        config: Config,
        slide_area: float,
        level: int,
    )

Source from the content-addressed store, hash-verified

478class Picture(ShapeElement):
479 @classmethod
480 def from_shape(
481 cls,
482 slide_idx: int,
483 shape_idx: int,
484 shape: PPTXPicture,
485 style: dict,
486 text_frame: TextFrame,
487 config: Config,
488 slide_area: float,
489 level: int,
490 ):
491 img_path = pjoin(
492 config.IMAGE_DIR,
493 f"{shape.image.sha1}.{shape.image.ext}",
494 )
495 if shape.image.ext == "wmf":
496 img_path = img_path.replace(".wmf", ".jpg")
497 if not pexists(img_path):
498 wmf_to_images(shape.image.blob, img_path)
499 elif shape.image.ext not in IMAGE_EXTENSIONS:
500 raise ValueError(f"unsupported image type {shape.image.ext}")
501 if not pexists(img_path):
502 with open(img_path, "wb") as f:
503 f.write(shape.image.blob)
504 style["img_style"] = {
505 "crop_bottom": shape.crop_bottom,
506 "crop_top": shape.crop_top,
507 "crop_left": shape.crop_left,
508 "crop_right": shape.crop_right,
509 }
510 picture = cls(
511 slide_idx,
512 shape_idx,
513 style,
514 [img_path, shape.name, ""],
515 text_frame,
516 slide_area,
517 level=level,
518 )
519 return picture
520
521 def build(self, slide: PPTXSlide):
522 shape = slide.shapes.add_picture(

Callers

nothing calls this directly

Calls 1

wmf_to_imagesFunction · 0.90

Tested by

no test coverage detected