A simple tool to compress all JPEG, PNG and GIF files losslessly in a folder,
by invoking the famous jpegtran
, optipng
and gifsicle
.
Smally uses file
command to determine file type, and it would keep
the file name and mtime unchnaged after compression!
- Using jpegtran to reduce all metadata.
- To compare among the original file, baseline format and progressive format files, choose the smallest one in size.
- Whenever possible, choose progressive format version.
Simply calling optipng to compress PNG, in the most crazy -o7 -zm1-9
level.
Simple calling gifsicle to compress GIF, by using -O3 --color 256
.
Smally needs jpegtran, optipng and gifsicle to do it's job.
$ sudo dnf install libjpeg-turbo-utils optipng gifsicle
sudo apt install libjpeg-turbo-progs optipng gifsicle
$ sudo bash _install_tools.sh JPEG
$ sudo bash _install_tools.sh PNG
$ sudo bash _install_tools.sh GIF
$ # or all in one command
$ sudo bash _install_tools.sh JPEG PNG GIF
This will compile and install the latest version of jpegtran, optipng and gifsicle at /usr/bin automatically. Be careful, the originals will be removed.
For the success of installation, you might also need:
$ sudo dnf install gcc make autoconf automake
$ bash test.sh
Normally:
$ # for all jpeg, png and gif
$ find <path/to/image_folder> -type f -exec bash smally.sh {} \;
$ # only jpeg
$ find <path/to/image_folder> -type f -exec bash smally.sh -t JPEG {} \;
$ # only png
$ find <path/to/image_folder> -type f -exec bash smally.sh -t PNG {} \;
$ # only gif
$ find <path/to/image_folder> -type f -exec bash smally.sh -t GIF {} \;
Or to use xargs' -P parameter
to take advantage of multi-core CPU:
$ # -P4 means 4 paralleled processes
$ find <pathname> -type f -print0 | xargs -0 -P4 -I{} bash smally.sh {}
For single file:
$ python3 smally.py --jpegtran <jpeg_file>
$ python3 smally.py --optipng <png_file>
$ python3 smally.py --gifsicle <gif_file>
For single file which you don't know the format:
$ bash smally.sh <filename>
This version (from V0.50) of smally is a total refactor one, old versions are too complicated, which I do not recommend!