Compress a Folder of Images with Python
Compress a Whole Folder of Images with Python (Resize + Subfolders + Smart PNG→JPEG) If you keep images for a blog, documentation, or a project folder, file size becomes a problem fast. Big images slow down pages, take space, and make sharing annoying. This script automates the cleanup: it walks through a folder (and subfolders), optionally resizes images to a max width, compresses JPEGs, compresses PNGs, and can convert PNG to JPEG when it actually makes sense. When this is useful Before publishing: shrink images for faster blog load times. Docs + screenshots: reduce size without manually exporting every file. Photo folders: compress camera images and keep a clean “compressed” copy. Automation: run it after exporting images from tools like Snipping Tool, Photoshop, or PowerPoint. What it does Walk subfolders automatically and keeps the same folder structure in the output. Resize to a max width (keeps aspect ratio, never upscales). Compress JPEG us...