
# https://www.globalsino.com/ICs/indexC.html
# Insert images to fit the boxes in a pptx file

import pptx
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
from PIL import Image
import os

MyPresentation = pptx.Presentation()

layout_two_content_2 = MyPresentation.slide_layouts[3]
Slide2 = MyPresentation.slides.add_slide(layout_two_content_2)
placeholder_content_2 = Slide2.placeholders[2]


layout_picture_with_caption_3 = MyPresentation.slide_layouts[8]
Slide3 = MyPresentation.slides.add_slide(layout_picture_with_caption_3)
placeholder_image_3 = Slide3.placeholders[1]


layout_title_and_content = MyPresentation.slide_layouts[1]
slide4 = MyPresentation.slides.add_slide(layout_title_and_content)
placeholder_content_4 = slide4.placeholders[1]

left = Inches(5)
top = Inches(3)
width = Inches(4)
height = Inches(2)

My_image = 'C:\GlobalSino\images\TestImages\ImagesOnly\ColoredImage.jpg'
im = Image.open(My_image)
width, height = im.size

placeholder_image_3.width = width
placeholder_image_3.height = height

My_picture_blank = Slide2.shapes.add_picture(My_image, left, top, width, height)

placeholder_image_3.insert_picture(My_image)

left_ph_r = placeholder_content_2.left
top_ph_r = placeholder_content_2.top
width_ph_r = placeholder_content_2.width
height_ph_r = placeholder_content_2.height

picture_ph_r = Slide2.shapes.add_picture(My_image, left_ph_r, top_ph_r, width_ph_r, height_ph_r)

MyPresentation.save(r'C:\20211101_Local_to_Google_Drive\Python\My_presentation.pptx')
# Open the ppt
os.startfile(r'C:\20211101_Local_to_Google_Drive\Python\My_presentation.pptx')


