How to Convert PNG to PowerPoint Slide in Python

This brief tutorial focuses on how to convert PNG to PowerPoint Slide in Python. It contains all the configuration information, step-wise process, and a runnable sample code to insert image in PPTX using Python. The application can be used in any operating system like Windows, Linux, or macOS that is configured with .NET Core and Python.

Steps to Insert Image in PPTX in Python

  1. Configure your IDE to use Aspose.Slides for Python via .NET
  2. Add reference to aspose.pydrawing and aspose.slides namespaces in your project to insert image in PPTX using Python
  3. Create an empty default presentation using a Presentation class object and access the first default slide of the newly created presentation
  4. Read the source PNG image as bytes from the disk and add it to the images collection of the presentation
  5. Insert a picture frame in the shapes collection of the selected slide using the added
  6. Convert PNG to PPTX in Python using the save method

The aforementioned steps guide the development of a PNG to PPTX converter in Python, where a new presentation containing a default slides collection and images collection is generated. The source image is loaded from the disk as a byte array, added to the first slide shapes collection as a picture frame and finally, the presentation with the image is saved on the disk.

Code to Add Image in PPTX in Python

While working with this feature to convert PNG to PPTX in Python, the Slide object is used to hold the reference to the target slide and IPPImage class object is used to hold the reference to the newly added image inside the images collection. The add_image method has a number of overloaded constructors that take different parameters like bytes, IPPImage object, Image object and memory stream.

In this tutorial, we have learnt to convert PNG file to PowerPoint in Python. If you want to explore the process of converting the PDF to presentation, refer to the article on how to convert PDF to presentation using Python.

 English