A powerful Bash script that automatically finds and converts all your images to WebP format. Just drop it in any directory and run - it will automatically find and convert every image in that directory and all its subdirectories. Perfect for bulk converting images across entire projects, websites, or even your entire system.
- Dead Simple: Drop the script anywhere and run it - that's it!
- Recursive Power: Automatically finds and converts ALL images in ALL subdirectories
- Set and Forget: Run it in your root directory to convert every image on your machine
- Non-Destructive: Creates WebP copies while preserving your original images
- Smart Processing: Handles multiple image formats (JPG, PNG, GIF, TIFF, BMP)
- Download
bash-image-to-webp.sh
- Make it executable:
chmod +x bash-image-to-webp.sh
- Place it anywhere and run:
./bash-image-to-webp.sh
That's it! The script will:
- Recursively search all subdirectories
- Find all supported image files
- Convert each to WebP format
- Keep your original files intact
- Place each WebP next to its original
Want to convert ALL images on your machine? Just run it from your root directory!
The script uses recursive directory scanning to:
- Find all JPG, JPEG, PNG, TIFF, BMP, and GIF files in the current directory and ALL subdirectories
- Convert each image to WebP using Google's cwebp tool
- Save the WebP version in the same location as the original
- Track and display progress as it works
No need to manually organize files or specify directories - it handles everything automatically!
- Bash shell environment
- WebP conversion tools (
cwebp
command-line tool)
While the default settings work great, you can customize the conversion:
./bash-image-to-webp.sh -q 80 -m 4
Common parameters:
-q <value>
: Quality factor (0-100)-m <value>
: Compression method (0-6)-mt
: Enable multi-threading-af
: Enable auto-filter
Before:
root_directory/
├── project1/
│ ├── images/
│ │ ├── photo.jpg
│ │ └── icon.png
│ └── assets/
│ └── banner.gif
└── project2/
└── images/
└── logo.png
After:
root_directory/
├── project1/
│ ├── images/
│ │ ├── photo.jpg
│ │ ├── photo.webp
│ │ ├── icon.png
│ │ └── icon.webp
│ └── assets/
│ ├── banner.gif
│ └── banner.webp
└── project2/
└── images/
├── logo.png
└── logo.webp
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
- Uses the WebP conversion tools from Google
- Inspired by the need for efficient web image optimization