I have many pictures in a folder, can you write a python script to copy them into a…
- User
I have many pictures in a folder, can you write a python script to copy them into a single powerpoint presentation
- Assistant
Yes, I can help you with that. Here's a Python script that uses the python-pptx library to create a PowerPoint presentation and insert images from a folder into separate slides.
First, you need to install the python-pptx library. You can do this by running the following command in your terminal or command prompt:
codepip install python-pptxOnce you have installed the library, you can use the following script to create a PowerPoint presentation and insert images from a folder:
pythonimport os import sys from pptx import Presentation from pptx.util import Inches # Set the path to the folder containing the images image_folder = "path/to/image/folder" # Create a new PowerPoint presentation prs = Presentation() # Loop through each image in the folder for filename in os.listdir(image_folder): if filename.endswith(".jpg") or filename.endswith(".png"): # Open the image file img_path = os.path.join(image_folder, filename) img = prs.images.open(img_path) # Add a new slide with the image slide = prs.slides.add_slide(prs.slide_layouts[6]) left = top = Inches(1) slide.shapes.add_picture(img, left, top, height=Inches(5), width=Inches(7)) # Save the PowerPoint presentation prs.save("images.pptx")Replace "path/to/image/folder" with the path to the folder containing the images you want to insert into the PowerPoint presentation. The script will loop through each image in the folder and add it to a new slide in the presentation. The images will be inserted with a height of 5 inches and a width of 7 inches, but you can adjust these values to fit your needs.
Once the script has finished running, you should have a new PowerPoint presentation named "images.pptx" in the same directory as the script.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.