Unknown model· unknown
from NVIDIA HelpSteer3 Preference
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
- Assistantpython
import os from pptx import Presentation # --- Configuration --- image_folder = "path/to/your/image/folder" # Replace with your folder path output_pptx = "output_presentation.pptx" # Name of the output PowerPoint file # --- Script --- # Create a new PowerPoint presentation prs = Presentation() # Get a list of image files in the folder image_files = [f for f in os.listdir(image_folder) if os.path.isfile(os.path.join(image_folder, f)) and f.lower().endswith(('.png', '.jpg', '.jpeg', '.gif'))] # Add each image as a slide for image_file in image_files: # Create a new slide slide = prs.slides.add_slide(prs.slide_layouts[6]) # Use a blank layout # Add the image to the slide img_path = os.path.join(image_folder, image_file) left = prs.slide_width / 2 - 200 # Adjust position as needed top = prs.slide_height / 2 - 150 # Adjust position as needed pic = slide.shapes.add_picture(img_path, left, top) # Save the presentation prs.save(output_pptx) print(f"Presentation created: {output_pptx}")Explanation:
-
Import Libraries:
os: For interacting with the file system (listing files in a folder).pptx: The Python library for working with PowerPoint presentations.
-
Configuration:
image_folder: Set this to the path of the folder containing your images.output_pptx: Set the desired name for the output PowerPoint file.
-
Create Presentation:
prs = Presentation(): Creates a new, empty PowerPoint presentation object.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.