0

I'm using pptx to run quality checks on some powerpoint presentations. I have to check if specific image is present in a presentation, however I'm finding it even in presentations where it's not present or where there actually are no images at all. This is the function i'm using, where gt_bytes are the bytes of the ground truth image i need to check exists.

def check_image_existance(gt_bytes: bytes, ppt: Presentation) -> list[dict]:
found_images = []
shapes = []
for slide_id, slide in enumerate(ppt.slides):
    for shape_id, shape in enumerate(slide.shapes):
        # image type
        if shape.shape_type == 13 or shape.shape_type == 14:
            if hasattr(shape, 'image'):
                image = shape.image
                image_bytes = image.blob
                if gt_bytes == image_bytes:
                    found_images.append({'slide_id':slide_id, 'shape_id':shape_id})
                    shapes.append(shape)

I'm exploring the found shapes properties but i cannot find anything that tells me whether they are visible or not. I have also checked if they are outside the bounds of the slide but that's not the case. All the images fall into the slide_type 13 so they are not placeholders.

  • Consider adding an item in your code that, when found, use debug.print to send the slide number and the object name to the Immediate window. From there, you can then go there to see what it's picking up by using the Selection Pane. Objects do have a '.Visible' property which can be manually toggled also in the Selection Pane. – RabbitMT Jul 31 '23 at 14:32
  • 1
    But that would valid for VBA, not for Python. @Francesco, Have you tried going through the .xml of the slide(s) instead? There are plenty of attributes that may not be accessible through the presentation (you may want to have a look at this https://stackoverflow.com/questions/76789267/) – Oran G. Utan Jul 31 '23 at 14:57
  • I'm wondering what exactly you mean by "visible or not"> Could this be a z order thing where the images are hidden behind eg text? – Martin Packer Jul 31 '23 at 15:29
  • 1
    No it's not a z-order problem. I just found out following @Bradipo suggestion that in the xml file the shapes have a "hidden" property that is not accessible from pptx, which in some of the shapes in my case is set to true – Francesco Pettini Jul 31 '23 at 15:31
  • I wrote a XSLT file in a related comment, that you could tweak to set the `Visible` to `True/"0"` in bulk. https://stackoverflow.com/a/76794390/18247317 – Oran G. Utan Jul 31 '23 at 16:04
  • Are you saying that the `hidden` attribute in the XML means the shapes list won't include the shape in question? – Martin Packer Aug 01 '23 at 06:58
  • @MartinPacker no, the shapes with the hidden attribute are included in the shape list, but they are not visible in the actual powerpoint presentation. Using pptx I don't see any way to check this property. – Francesco Pettini Aug 01 '23 at 08:27
  • Not a complete solution but the answer lies in parsing the XML for each shape to find this attribute. – Martin Packer Aug 02 '23 at 09:02

0 Answers0