# https://www.globalsino.com/ICs/
# Find image names in a pptx file

from pptx import Presentation
import re

pptxFilePath = r"C:\0Python\pptxTest\pptxTest1.pptx"
openedPPTXfile = open(pptxFilePath, 'rb')
MyPresentation = Presentation(openedPPTXfile)

def FindImagesInPPTXfile(imageShape):
    imgExtension = imageShape.content_type
    filePattern = '(.jpg$|.jpeg$|.png$|.gif$|.tif$)'
    image = re.search(filePattern, imgExtension)
    print("The image type, image.group(0), is: ", image.group(0))
    return image.group(0)
			

for slide in MyPresentation.slides:
    for shape in slide.shapes:
        print("\n")
        print("shape.image is ", shape.image)
        if shape.image:
            if FindImagesInPPTXfile(shape.image):
                print("The image file name, shape.image.filename, is:: ", shape.image.filename)
openedPPTXfile.close()
