scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.26k stars 498 forks source link

how to activate and utilize the MORPH transision feature #942

Open nnako opened 5 months ago

nnako commented 5 months ago

Hi,

I was wondering if it was currently possible to activate and use the morph feature for transitioning an image element between two slides (thus changing its location, orientation, zoom, ...). If there is the possibility to configure morphing using python-pptx, how could it be done? And if not yet, where whould I start digging into the PPTX file and the python-pptx code base to work out a solution?

Thanks.

nnako commented 3 months ago

meanwhile, I tested some examples and found out that the only difference between a PPTX file without and with morphing would basically be the following.

Assuming, on slide 1 there was a picture and on slide 2 there was the same picture (same name as seen in the selection pane) at a maybe different position and a different zoom level, ... . Then, the difference between the two files

ppt / slides / slide1.xml

and

ppt / slides / slide2.xml

would be an additional constant xml text at the bottom of slide2.xml (compared to slide1.xml) which looks like this:

<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <mc:Choice xmlns:p159="http://schemas.microsoft.com/office/powerpoint/2015/09/main" Requires="p159">
        <p:transition spd="slow" xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" p14:dur="2000">
            <p159:morph option="byObject"/>
        </p:transition>
    </mc:Choice>
    <mc:Fallback>
        <p:transition spd="slow">
            <p:fade/>
        </p:transition>
    </mc:Fallback>
</mc:AlternateContent>

So, a starting point might be to localize where in the code base it would be best to cause this xml text block to be written into the appropriate file. This would cause a morph effect whenever the transition goes from slide 1 to slide 2 in presentation mode. There is one oddity, though. As soon as the slides contain un-filled placeholders, the morph will not work. So, the code would have to deal with this as well.

Any hints, where to find a suitable place within the code base to start a 1st implementation?

MartinPacker commented 3 months ago

In md2pptx I attach an AlternateContent element under the slide element.

Might help.

nnako commented 3 months ago

Hi @MartinPacker , thanks. Wouldn't the functions you already developed within md2pptx not be perfectly suitable to be integrated in the python-pptx code base? At least the ones which make activating shadows, morph, and other effects much easier to be realized?

MartinPacker commented 3 months ago

Possibly. I'm not authorised by my employer (IBM) yet to contribute to the python-pptx base. Given the (understandably) high barrier to contributing to python-pptx I probably won't pursue that.

Also the functions probably aren't watertight.

So, feel free to borrow them. But I dont think I'm going to be the one to contribute them to python-pptx.

I'd be interested, though, in whether they need enhancing - to add more effects. I'd then work on those and add them to md2pptx. Or someone else can contribute.