give me a python script that takes input folder path as static then downscale every…
- User
give me a python script that takes input folder path as static
then downscale every image in that folder with 50% and save as best quality jpg and overwrite image
Assistant
import os import sys from PIL import Image # Set the input folder path as a static variable input_folder_path = "path/to/input_folder" # Iterate over the files in the input folder for file in os.listdir(input_folder_path): # Check if the file is an image if file.endswith((".jpg", ".jpeg", ".png")): # Open the image image = Image.open(os.path.join(input_folder_path, file)) # Downscale the image by 50% image = image.resize((int(image.width * 0.5), int(image.height * 0.5))) # Save the downscaled image as a high-quality JPG image.save(os.path.join(input_folder_path, file), "JPEG", quality=95) # Print a message to indicate that the image has been downscaled print(f"Downscaled {file} to 50% of its original size.")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.