image-optimiser is a Linux shell utility that losslessly compresses image files in place.
It recursively scans one or more paths, optimises supported files, and prints per-file and total size reduction.
- Lossless optimisation for
PNG,JPG, andJPEG - Recursive directory scanning
- Multiple input paths in one run
- Keeps image metadata and file permissions where supported by the backend tools
- Reports before/after size for each file and for the full run
The script delegates optimisation to proven CLI tools:
PNG->oxipngJPG/JPEG->jpegoptim
The files are edited in place, so no separate output folder is created.
- Linux
- Bash
find,awk,du,numfmt(usually available in GNU coreutils/findutils)oxipngjpegoptim
Arch Linux:
sudo pacman -S --needed oxipng jpegoptim coreutils findutils gawkDebian/Ubuntu:
sudo apt update
sudo apt install -y oxipng jpegoptim coreutils findutils gawkFedora:
sudo dnf install -y oxipng jpegoptim coreutils findutils gawkMake the script executable:
chmod +x optimise-image.shRun it with one or more files/directories:
./optimise-image.sh <path> [<path> ...]Examples:
# Optimise all supported images in a directory tree
./optimise-image.sh ./assets
# Optimise files and directories together
./optimise-image.sh ./assets ./public/logo.png ./screenshotsFile #1: './assets/logo.png'
Size: 182K -> 156K
File #2: './assets/banner.jpg'
Size: 1.5M -> 1.3M
Finished processing 2 images
Size: 1.7M -> 1.4M
- Only
png,jpg, andjpegfiles are processed. - Scanning is recursive for directory inputs.
- Non-existent paths are skipped with an error message.
- Compression is lossless, but always keep backups for critical assets.
oxipng: command not found or jpegoptim: command not found
- Install missing dependencies from the Requirements section.
Permission denied
- Ensure the script is executable:
chmod +x optimise-image.sh - Ensure you have write permission for the target files.
No files processed
- Verify your path exists and contains
png,jpg, orjpegfiles.
Contributions are welcome.
Please:
- keep the pull requests focused and consistent with the existing style.
- update the documentation when the behaviour changes.
Licensed under the GNU General Public License v3.0 or later. See LICENSE for details.