Lossless Image Optimization (CLI): IMGULT

Posted By Pascal Jordin


03. May 2019|07:14 Uhr

Do you know the problem that a Google PageSpeed Insights always complains that the images on a website are still too big? I have always found it too much effort to optimize every small picture again via Photoshop or other tools. At some point I came across this small but fine CLI tool called IMGULT. It searches recursively for supported image formats, optimizes them automatically and lossless with the necessary library. Supported formats: GIF, JPG, PNG and SVG 


Some dependencies are needed for the optimizations, theoretically you can only install the desired packages. 

Install dependencies 

sudo apt-get update
sudo apt-get install -y jpegoptim optipng pngquant gifsicle exiv2 pkg-config libpng-dev cmake autoconf automake libtool nasm make pkg-config git
npm install -g svgo

Install Mozjpeg

The installation of Mozjpeg has changed a bit since the last version. Therefore the procedure looks like this:

cd ~
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg
mkdir build && cd build
sudo cmake -G"Unix Makefiles" ../
sudo make install
sudo ln -s /opt/mozjpeg/bin/jpegtran /usr/bin/mozjpeg
cd ~

Install IMGULT

Finally, we clone the repo from Github and install IMGULT into our local/bin

wget -N https://raw.githubusercontent.com/ryanpcmcquen/image-ultimator/master/imgult; sudo install -m755 imgult /usr/local/bin/; rm imgult

IMGULT Website: https://imgult.github.io/

Optimization before/after deployment 

Manual optimization of images is so 2000! Today such commands are simply put into the pre-commit hook of your development environment or into the deployment of your project. This is what my Forge Deploy Script looks like for this website: 

cd /home/forge/jordin.eu
git pull origin master
php please clear:cache
php please search:update
cd site/themes/jordin
npm install 
gulp --production
cd -
echo "" | sudo -S service php7.3-fpm reload

What does your workflow look like for such tasks? Do you know any other tools I should have a look at? :)