How to bulk optimize images using Mozjpeg on ubuntu server?

2k views Asked by At

I want to optimize images bulk and i read mozjpeg`s usage , there no have how to work bulk on server.

Could you tell me how to optimize that?

Thank you.

1

There are 1 answers

1
DIYGUY On

Tested on Ubuntu 16.04 to batch or bulk optimize all jpegs recursively given any folder using mozjpeg pre-compiled binaries. Execute the following commands:

First download and install mozjpeg... For 64bit:

wget https://mozjpeg.codelove.de/bin/mozjpeg_3.2_amd64.deb
dpkg -i mozjpeg_3.2_amd64.deb

For 32bit:

wget https://mozjpeg.codelove.de/bin/mozjpeg_3.2_i386.deb
dpkg -i mozjpeg_3.2_i386.deb

Then link mozjpeg's jpegtran...

ln -s /opt/mozjpeg/bin/jpegtran /usr/bin/jpegtran

Then download this perl script which will recursively scan for jpegs, optimize with the new jpegtran, and print results.

wget https://gist.githubusercontent.com/aksuited/96ea6144d9b62befbce23fd62b3b7b4d/raw/e31a74da9d7eaa6004969716f49c08e8d0a4de62/optimize_jpegs.pl

give the script permissions...

chmod 755 optimize_jpegs.pl

execute script...

optimize_jpegs.pl /path/to/jpegs

Sample Output:

# ./optimize_jpegs.pl /
Inspecting //2.2.jpg
 -- Huffman table optimization: saved 15681 bytes (orig 93901)
Inspecting //28ga 500ft 4oz 1.jpg
 -- Huffman table optimization: saved 3055 bytes (orig 25897)
Inspecting //104.jpg
 -- Huffman table optimization: saved 9566 bytes (orig 48080)
Inspecting /usr/share/doc/nodejs/full-white-stripe.jpg
Inspecting /usr/share/doc/nodejs/thin-white-stripe.jpg


----------------------------
  Sumary
----------------------------

  Inspected 5 JPEG files.
  Modified 3 files.
  Huffman table optimizations: 3
  Progressive JPEG optimizations: 0
  Total bytes saved: 28302 (orig 167878, saved 16.85%)