How to build mozjpeg on macOS (with PNG support)
1 min readOct 15, 2021
If you have installed mozjpeg library as a package via brew — you may see message about unsupported format by trying to compress .PNG (and even JPG) pictures.
You should to build this library manually, and if you are using macOS — lets follow these steps:
$ cd ~/
$ wget https://codeload.github.com/mozilla/mozjpeg/zip/master -O mozjpeg-master.zip
$ unzip mozjpeg-master.zip
1. Building
$ cd ~/mozjpeg-master
$ mkdir build && cd build
$ sudo cmake -G"Unix Makefiles" -DPNG_SUPPORTED=ON ../
2. Make links
You should make it for use mozjpeg command in command line
!!!Here is important to use/usr/local
instead of just/usr/bin
in macOS
sudo ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozjpeg
sudo ln -s /opt/mozjpeg/bin/jpegtran /usr/bin/mozjpegtran
Using
Compress (lossy)
$ mozjpeg -quality 70 bla.png > new_bla.png
Optimize (lossless)
$ mozjpegtran -optimize -progressive new_bla.png > super_new_bla.png
Try to use these both commands to get most better result!