Last modified: Aug 23, 2026

Python PPTX Add Picture: Easy Guide

Adding pictures to PowerPoint slides is a common task. The python-pptx library makes this simple. You can insert images from your computer or from the web. This guide shows you how to do it step by step.

You will learn about the add_picture method. We will cover positioning, sizing, and cropping. By the end, you can create professional slides with images. Let's start.

Why Use python-pptx for Images?

Manual slide creation is slow. Using Python saves time. You can automate reports, presentations, and more. The library is free and easy to install. It works on Windows, Mac, and Linux.

With a few lines of code, you can add multiple images. You can also control their exact placement. This is great for templates and branding. For more template ideas, check out our guide on using templates for easy slides.

Installing the Library

First, you need to install python-pptx. Open your terminal or command prompt. Then run this command:


pip install python-pptx

Wait for the installation to finish. That's it. You are ready to code. If you have issues, check your Python version. It should be 3.6 or higher.

Basic Image Addition

The core function is add_picture. This method belongs to a slide object. You need to specify the image file path. Here is a simple example.


from pptx import Presentation

# Create a presentation object
prs = Presentation()

# Use the default slide layout (blank)
slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(slide_layout)

# Add a picture from a file
slide.shapes.add_picture('my_image.png', 0, 0)

# Save the presentation
prs.save('output.pptx')
print("Presentation saved successfully!")

In this example, the image is placed at position (0,0). This is the top-left corner. The image is added in its original size. Let's see the output.


Presentation saved successfully!

You now have a PowerPoint file with one picture. But this is just the start. You can control everything.

Specifying Position and Size

The add_picture method accepts extra arguments. You can set the left and top position. You can also set the width and height. All values are in pixels by default.


from pptx import Presentation
from pptx.util import Inches, Pt

prs = Presentation()
slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(slide_layout)

# Add a picture with position and size
slide.shapes.add_picture(
    'my_image.png',
    left=Inches(1),
    top=Inches(1),
    width=Inches(5),
    height=Inches(3)
)

prs.save('positioned_image.pptx')
print("Image added with custom position and size.")

Here, we used Inches to set the units. The image is 1 inch from the left and top. It is 5 inches wide and 3 inches tall. This gives you precise control.

You can also use Cm or Emu for other units. Emu is the smallest unit. The library converts everything internally. This makes it flexible.

Maintaining Aspect Ratio

When you set both width and height, the image may stretch. To avoid this, specify only one dimension. The library will calculate the other one automatically.


from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(slide_layout)

# Add picture with only width, height auto-calculated
slide.shapes.add_picture(
    'my_image.png',
    left=Inches(2),
    top=Inches(2),
    width=Inches(6)  # Height will be auto
)

prs.save('aspect_ratio_image.pptx')
print("Image added with preserved aspect ratio.")

This is very useful for logos and photos. It prevents distortion. Your images will always look professional.

Cropping Images

You can also crop images. This is done with the crop_left, crop_right, crop_top, and crop_bottom properties. Values range from 0.0 to 1.0. A value of 0.5 crops half of that side.


from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(slide_layout)

# Add a picture and crop it
pic = slide.shapes.add_picture(
    'large_image.png',
    left=Inches(1),
    top=Inches(1),
    width=Inches(4)
)

# Crop 20% from the left side
pic.crop_left = 0.2
# Crop 10% from the bottom
pic.crop_bottom = 0.1

prs.save('cropped_image.pptx')
print("Image cropped successfully.")

Cropping is great for focusing on specific parts. You can do it without editing the original file. This keeps your workflow clean.

Adding Images from the Web

You can also add images from URLs. First, download the image with Python. Then, use the same add_picture method. Here is an example using requests.


import requests
from pptx import Presentation
from pptx.util import Inches

# Download an image from the web
url = 'https://example.com/logo.png'
response = requests.get(url)

# Save it locally
with open('web_image.png', 'wb') as f:
    f.write(response.content)

prs = Presentation()
slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(slide_layout)

# Add the downloaded image
slide.shapes.add_picture(
    'web_image.png',
    left=Inches(1),
    top=Inches(1),
    width=Inches(3)
)

prs.save('web_image.pptx')
print("Image from web added.")

Make sure you have the requests library installed. You can install it with pip install requests. This method is handy for dynamic content.

For a more detailed walkthrough, see our complete picture guide. It covers many more scenarios.

Working with Multiple Images

You can add as many images as you want. Just call add_picture multiple times. Each call places a new image on the slide. You can stack them or place them side by side.


from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(slide_layout)

# Add first image
slide.shapes.add_picture(
    'image1.png',
    left=Inches(0.5),
    top=Inches(1),
    width=Inches(4)
)

# Add second image next to it
slide.shapes.add_picture(
    'image2.png',
    left=Inches(5),
    top=Inches(1),
    width=Inches(4)
)

prs.save('multiple_images.pptx')
print("Two images added successfully.")

This is perfect for comparisons or galleries. You can also loop through a list of images. This automates the process completely.

Using Templates with Images

Templates often have placeholders for images. You can fill these placeholders with your pictures. This is more advanced but very powerful. You can also add pictures to specific layouts.

If you want to master templates, read our step-by-step image guide. It shows you how to work with placeholders effectively.

Common Errors and Fixes

Sometimes you might get errors. The most common one is file not found. Make sure your image path is correct. Use absolute paths if needed.

Another error is unsupported file format. python-pptx supports PNG, JPEG, GIF, and BMP. If you use other formats, convert them first. The library will throw an error otherwise.

Check your slide dimensions too. If the image is too large, it may go off-slide. Always set proper width and height. Use Inches or Cm for clarity.

Conclusion

Adding pictures with python-pptx is straightforward. You learned about the add_picture method. You can set position, size, and crop images. You can also add images from the web and use templates.

This skill is essential for automating presentations. It saves you hours of manual work. Practice with different images and layouts. You will become proficient quickly.

Remember to always test your code. Check the output file to ensure everything looks right. With these tools, you can create stunning slides effortlessly.