Search code examples
pythonpython-2.7python-pptx

python pptx align image to center of slide


I need to add an image to a pptx slide, and want to locate it in the center of the slide, without having to calculate the size and alignment manually,

I found a question about doing so with text: question about center aligning text

And the documentation about doing so with text: documentation about center aligning text

But can't find a way to do it for an image,

Ideas?


Solution

  • It's not going to work the same way as text; there's no center justification or alignment property on an image. You'll need to use a formula.

    image.left = (prs.slide_width - image.width) / 2