JPG and PNG image optimization on Linux

JPG optimization

Download jpegoptim from https://github.com/tjko/jpegoptim

git clone git@github.com:tjko/jpegoptim.git

Install jpegoptim

./configure
make
make strip
make install

Use jpegoptim

# compress one file
jpegoptim file.jpg
# compress multiple files
jpegoptim file.jpg file1.jpg file2.jpg

Compress image to around 50k

jpegoptim file.jpg -size=50k --strip-all

Compress a folder of images

cd FOLDER
jpegoptim --size=250k *.jpg

PNG optimization

Download optiPNG from http://optipng.sourceforge.net/

Install optiPNG

cd <folder> 
./configure 
make
make install

Use optiPNG

optipng logo.png
optipng *.png

Imagemagick

https://www.imagemagick.org/script/install-source.php

git clone git@github.com:ImageMagick/ImageMagick.git
$ cd ImageMagick-7.0.7
$ ./configure
$ make
sudo make install
sudo ldconfig /usr/local/lib

# test 
/usr/local/bin/convert logo: logo.gif

Convert file

https://www.imagemagick.org/script/convert.php

magick convert rose.jpg rose.png

Convert and resize image

magick convert rose.jpg -resize 50% rose.png

Optimization

convert puzzle.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB puzzle_converted.jpg