
# https://www.globalsino.com/ICs/indexC.html
# Rotate an image in a pptx file with the same lateral dimension

from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
import os
import cv2

MyPresentation = Presentation()

img1 = r"C:\0Python\images\screenshots\TopRightCorner.png"

im = cv2.imread(img1)

im_real_height = im.shape[0]
im_real_width = im.shape[1]

Slide1_Register = MyPresentation.slide_layouts[5]
Slide1 = MyPresentation.slides.add_slide(Slide1_Register)
title1  = Slide1.shapes.title
title1.text = "Data"

def imageOrientation(theAngle, height_or_width, x, y, img):
    half_w = im_real_width*height_or_width/im_real_height/2 ###
    if theAngle == 90:
        from_left_2 = Inches(x)
        from_top_2 = Inches(y)
        add_picture_2 = Slide1.shapes.add_picture(img1, from_left_2, from_top_2, width = None, height =Inches(height_or_width))

        from_left_2 = Inches(x+(height_or_width/2)-half_w) ###
        from_top_2 = Inches(y-(height_or_width/2)+half_w) ####
        add_picture_2 = Slide1.shapes.add_picture(img1, from_left_2, from_top_2, width =None, height =Inches(height_or_width))
        add_picture_2.rotation = 90

    else:
        if theAngle == -90:
            from_left_2 = Inches(x)
            from_top_2 = Inches(y)
            add_picture_2 = Slide1.shapes.add_picture(img1, from_left_2, from_top_2, width = None, height =Inches(height_or_width))

            from_left_2 = Inches(x+(height_or_width/2)-half_w) ###
            from_top_2 = Inches(y-(height_or_width/2)+half_w) ####
            add_picture_2 = Slide1.shapes.add_picture(img1, from_left_2, from_top_2, width =None, height =Inches(height_or_width))
            add_picture_2.rotation = -90

        else:
            from_left_2 = Inches(x)
            from_top_2 = Inches(y)
            add_picture_2 = Slide1.shapes.add_picture(img1, from_left_2, from_top_2, width =Inches(height_or_width), height =None)

imageOrientation(0, 1.5, 1.5, 1.4, img1)
imageOrientation(90, 1.5, 3.5, 1.4, img1)
imageOrientation(-90, 1.5, 6.5, 1.4, img1)
    
MyPresentation.save(r'C:\0Python\Test.pptx')





