gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
Hi, could you please modify this Python script to work recursively on images in…
- User
Hi, could you please modify this Python script to work recursively on images in subdirectories, instead of just images in the current working directory:
import glob from PIL import Image def find_smallest_pngs(): # Get all PNG files in the current directory image_files = glob.glob("*.[jJ][pP][gG]") + glob.glob("*.[pP][nN][gG]") + glob.glob("*.[wW][eE][bB][pP]") if not image_files: print("No image files found in the current directory.") return image_data = [] # Process each PNG file for file in image_files: try: with Image.open(file) as img: width, height = img.size pixel_count = width * height image_data.append((pixel_count, width, height, file)) except Exception as e: print(f"Skipping invalid file '{file}': {str(e)}") continue if not image_data: print("No valid PNG files could be processed.") return # Sort by pixel count (ascending) and select top 10 sorted_images = sorted(image_data, key=lambda x: x[0]) top_10 = sorted_images[:10] # Print results print("\nTop 10 smallest PNG images by pixel count (width × height):") print(f"{'Rank':<6} {'Filename':<50} {'Width':<8} {'Height':<8} {'Pixels':<10}") for idx, (pixels, w, h, name) in enumerate(top_10, 1): print(f"{idx:<6} {name[:47] + '...' if len(name) > 30 else name:<50} {w:<8} {h:<8} {pixels:<10}") if __name__ == "__main__": find_smallest_pngs()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.