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, certainly! Here is a sample Python script that you can use to copy all the pictures in a folder into a single PowerPoint presentation:
pythonimport os from pptx import Presentation from pptx.util import Inches # Set the path to the folder containing the pictures folder_path = 'path/to/folder' # Create a new PowerPoint presentation prs = Presentation() # Loop through all the files in the folder for filename in os.listdir(folder_path): if filename.endswith(".jpg") or filename.endswith(".png"): # Add a new slide to the presentation slide = prs.slides.add_slide(prs.slide_layouts[6]) # Add the picture to the slide left = top = Inches(1) pic = slide.shapes.add_picture(os.path.join(folder_path, filename), left, top, height=Inches(5), width=Inches(7)) # Save the PowerPoint presentation prs.save('sample.pptx')This script uses the
python-pptxlibrary to create and modify the PowerPoint presentation. You'll need to install the library by runningpip install python-pptxin your command prompt or terminal.Note that this script assumes that all the pictures in the folder are either JPEGs or PNGs. If your pictures are in a different format, you'll need to modify the
ifstatement accordingly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.