Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Donate Latest Release Build Status License: GPL v3

Image Optimiser

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.

Features

  • Lossless optimisation for PNG, JPG, and JPEG
  • 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

How It Works

The script delegates optimisation to proven CLI tools:

  • PNG -> oxipng
  • JPG/JPEG -> jpegoptim

The files are edited in place, so no separate output folder is created.

Requirements

  • Linux
  • Bash
  • find, awk, du, numfmt (usually available in GNU coreutils/findutils)
  • oxipng
  • jpegoptim

Install Dependencies

Arch Linux:

sudo pacman -S --needed oxipng jpegoptim coreutils findutils gawk

Debian/Ubuntu:

sudo apt update
sudo apt install -y oxipng jpegoptim coreutils findutils gawk

Fedora:

sudo dnf install -y oxipng jpegoptim coreutils findutils gawk

Usage

Make the script executable:

chmod +x optimise-image.sh

Run 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 ./screenshots

Output Example

File #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

Notes and Limitations

  • Only png, jpg, and jpeg files 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.

Troubleshooting

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, or jpeg files.

Contributing

Contributions are welcome.

Please:

  • keep the pull requests focused and consistent with the existing style.
  • update the documentation when the behaviour changes.

License

Licensed under the GNU General Public License v3.0 or later. See LICENSE for details.

About

Linux shell utility that losslessly compresses image files in place

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages