Categories We Write About

Batch rename image files by resolution

To batch rename image files by their resolution (e.g., width x height), you can use a script to extract the resolution of each image and rename the files accordingly. Below is a Python script using the Pillow library:


✅ Python Script: Rename Images by Resolution

python
import os from PIL import Image # Set the directory containing your images image_folder = 'path/to/your/images' # Supported image file extensions image_extensions = ['.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff'] # Rename files for filename in os.listdir(image_folder): file_path = os.path.join(image_folder, filename) base, ext = os.path.splitext(filename) if ext.lower() in image_extensions: try: with Image.open(file_path) as img: width, height = img.size new_name = f"{width}x{height}_{base}{ext}" new_path = os.path.join(image_folder, new_name) # Avoid overwriting existing files if not os.path.exists(new_path): os.rename(file_path, new_path) print(f"Renamed: {filename} -> {new_name}") else: print(f"Skipped (exists): {new_name}") except Exception as e: print(f"Error processing {filename}: {e}")

🔧 Notes:

  • Replace path/to/your/images with your actual directory.

  • It renames files to format like 1920x1080_oldfilename.jpg.

  • Avoids overwriting files with same name.

Let me know if you want the new names to be just resolution (e.g., 1920x1080.jpg), numbered (e.g., image_1920x1080_01.jpg), or if you’re working in Windows and want a PowerShell or batch script instead.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About