Lossless Image Compressions using Docker
I tried couple of existing docker containers to compress images without success. Both suffered a sever security threat because of being ‘very old’. There was only one complete tool zevilz/zImageOptimizer and that too didn’t have docker (have sent a pull request) meaning that you have to install everything for the compression.
I turned it into docker image over varunbatrait/zimageoptimizer
My primary requirement was to use this image to shrink images every week or a fortnight on few blogs or images shot by my camera.This docker image is ideal for that.
It supports cron and as a web user compressing images helps in saving your BW and thus contribute you scalability.
How to use?
There are two ways to do it:
Maintain the marker
Marker is just a file with a timestamp of last run command. If new images are added, zImageOptimizer will consider only new image.
docker run -it -u "$UID:$GID" -d --volume /mnt/ImagesHundred/marker:/work/marker --volume /mnt/ImagesHundred/images/:/work/images/ -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro varunbatrait/zimageoptimizer ./zImageOptimizer.sh -p /work/images/ -q -n -m /work/marker/marker
Not Maintaining the marker
docker run -u "$UID:$GID" --volume /path/to/images:/work/images -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro varunbatrait/zimageoptimizer
- Images are losslessly compressed – no quality loss.
- You don’t have to install dependencies on every server. It is in docker.
- You can use it with cron.
Pain with PNGs
Please note that PNGs images can take significant time (15-25 seconds per image) and CPU (almost 100%). Just stay calm! 🙂