

# https://www.globalsino.com/ICs/
# Align the top-left corner of the image to the center of the slide

from pptx import Presentation
from pptx.util import Inches
from PIL import Image

MyPresentation = Presentation()

Slide_Register = MyPresentation.slide_layouts[5]
Slide = MyPresentation.slides.add_slide(Slide_Register)
title  = Slide.shapes.title
title.text = "Experimental Images"

# Change slide sizes to Widescreen
slide_size = (16, 9)
MyPresentation.slide_width, MyPresentation.slide_height = Inches(slide_size[0]), Inches(slide_size[1])

# Convert pixels to inches
def px_to_inches(path):
    im = Image.open(path)
    width = im.width/im.info['dpi'][0] # dpi: image resoution
    height = im.height/im.info['dpi'][1]
    return (width, height)

theImage = r"C:\0Python\images\TheJob\JobB\ImagePool (3).jpg"

img = px_to_inches(theImage)
left = Inches(slide_size[0] - img[0])/2
top = Inches(slide_size[1] - img[1])/2
pic = Slide.shapes.add_picture(theImage, left, top, width =None, height =None)

MyPresentation.save(r"C:\0Python\images\PPTtest_World_JobDescription.pptx")
