Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile with MozJPEG #41

Closed
adrianmihalko opened this issue Dec 17, 2016 · 11 comments
Closed

Compile with MozJPEG #41

adrianmihalko opened this issue Dec 17, 2016 · 11 comments

Comments

@adrianmihalko
Copy link

adrianmihalko commented Dec 17, 2016

I am not a CLI master, can you please provide me more details about how to compile with MozJPEG support?

I tried:

$ ls /opt/mozjpeg
bin  include  lib64  share
@ubuntu:~/scripts/jpegoptim$ ./configure CPPFLAGS=-I/opt/mozjpeg/bin/ LDFLAGS=-L/opt/mozjpeg/include/
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for jpeg_read_header in -ljpeg... yes
checking for floor in -lm... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for unistd.h... (cached) yes
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking for string.h... (cached) yes
checking libgen.h usability... yes
checking libgen.h presence... yes
checking for libgen.h... yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking size of long... 8
checking size of int... 4
checking for getopt_long... yes
checking for mkstemps... yes
checking for labs... yes
checking for broken jmorecfg.h (METHODDEF)... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged

$ ./jpegoptim --help
Wrong JPEG library version: library is 80, caller expects 62

mozilla/mozjpeg#232 (comment)

@adrianmihalko
Copy link
Author

adrianmihalko commented Dec 17, 2016

I researched more and I tried:

n@ubuntu:~/scripts/jpegoptim$ ./configure CPPFLAGS=-I/opt/mozjpeg/include LDFLAGS=-L/opt/mozjpeg/lib64
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for jpeg_read_header in -ljpeg... yes
checking for floor in -lm... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for unistd.h... (cached) yes
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking for string.h... (cached) yes
checking libgen.h usability... yes
checking libgen.h presence... yes
checking for libgen.h... yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking size of long... 8
checking size of int... 4
checking for getopt_long... yes
checking for mkstemps... yes
checking for labs... yes
checking for broken jmorecfg.h (METHODDEF)... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
madrian@ubuntu:~/scripts/jpegoptim$ ls /opt/mozjpeg/include
jconfig.h  jerror.h  jmorecfg.h  jpeglib.h  turbojpeg.h
ubuntu:~/scripts/jpegoptim$ make
gcc  -g -O2 -I/opt/mozjpeg/include -DHAVE_CONFIG_H   -c -o jpegoptim.o jpegoptim.c
gcc  -g -O2 -I/opt/mozjpeg/include -DHAVE_CONFIG_H   -c -o jpegdest.o jpegdest.c
gcc  -g -O2 -I/opt/mozjpeg/include -DHAVE_CONFIG_H   -c -o misc.o misc.c
gcc  -g -O2 -I/opt/mozjpeg/include -DHAVE_CONFIG_H -o jpegoptim jpegoptim.o jpegdest.o misc.o  -L/opt/mozjpeg/lib64 -lm -ljpeg  
ubuntu:~/scripts/jpegoptim$ ./jpegoptim --version
jpegoptim v1.4.4  x86_64-unknown-linux-gnu
Copyright (c) 1996-2016, Timo Kokkonen

libjpeg version: 6b  27-Mar-1998
Copyright (C) 1991-2014 The libjpeg-turbo Project and many others

Now it runs fine, but I am not sure if it is using the mozjpeg library.

 jpegoptim -m 91 120,902.jpg -d ./hello/
 cjpeg -quality 91 120,902.jpg > ./hello/comp91.jpg

-rw-rw-r-- 1 madrian madrian 91073 Dec 17 15:28 120,902.jpg
-rw-rw-r-- 1 madrian madrian 91089 Dec 17 15:30 comp91.jpg

So the 2 files has different file sizes.

@HeadstrongCatgirl
Copy link

HeadstrongCatgirl commented Jun 26, 2017

Had to add /opt/mozjpeg/lib64 to ldconfig manually, but now jpegoptim creates files 3-4% smaller than before.
echo '/opt/mozjpeg/lib64/' > /etc/ld.so.conf.d/mozjpeg.conf && ldconfig

@aolin480
Copy link

aolin480 commented Sep 6, 2017

a buddy and I were just talking about this yesterday and he came up with these instructions, which also work on Mac OS if you have homebrew installed (for pkg tools). Just for reference if anyone wants the steps to do this. Props to @wseemann :

# get the depdendencies (view brew)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install pkg-config autoconf automake libtool nasm

# get mozjpeg
wget https://github.com/mozilla/mozjpeg/releases/download/v3.2/mozjpeg-3.2-release-source.tar.gz
tar -xvf mozjpeg-3.2-release-source.tar.gz
cd mozjpeg-3.2-release-source

# build mozjpeg
autoreconf -fiv
./configure
make
sudo make install

# get jpegoptim
git clone https://github.com/tjko/jpegoptim.git
cd jpegoptim.git

# build jpegoptim
./configure CPPFLAGS=-I/opt/mozjpeg/include LDFLAGS=-L/opt/mozjpeg/lib
make
sudo make install

# run it (from terminal)
jpegoptim -V

@ianamk
Copy link

ianamk commented Jul 29, 2018

a bit late but it might be helpful to somebody else
I compiled it with mozjpeg on windows with gcc just by using the switch
./configure --with-libjpeg=/d/mozjpeg-3.3.1/.libs
I had to manually copy the mozjpeg include files (jconfig.h, jerror.h, jmorecfg.h, jpeglib.h, turbojpeg.h) to C:\msys64\mingw64\include\ or the ./configure script couldn't find them
but this is doable on linux too if you don't want to install the mozjpeg binaries just pass the path to where libjpeg.a is and copy the above mentioned include files to /usr/local/include (you can delete them after compile)

@dvershinin
Copy link

Users of CentOS / RedHat 7 may want to install jpegoptim compiled with MozJPEG using these instructions (no compilation required, ready to install package).

@ozcoder
Copy link

ozcoder commented Jun 25, 2019

If you are OK with using ABI 8 of libjpeg then this works.
Build mozjpeg and install to prefix of /usr/local

mkdir build
cd build
cmake -GUnix Makefiles ../ -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_JPEG8=1
make
sudo make install/strip

Now build jpegoptim

./configure --with-libjpeg=/usr/local
make
make strip
sudo make install

Now as root, tell jpegoptim where the library is
echo '/usr/local/lib/' > /etc/ld.so.conf.d/jpegoptim.conf

@adrianmihalko
Copy link
Author

adrianmihalko commented Aug 23, 2019

Guys, can you verify what should be the output when mozjpeg is enabled?

I am compiling with

@ubuntu:~/scripts/jpegoptim$ ./configure CPPFLAGS=-I/opt/mozjpeg/include LDFLAGS=-L/opt/mozjpeg/lib64 --with-libjpeg=/opt/mozjpeg/lib64
@ubuntu:~/scripts/jpegoptim$ make
gcc  -g -O2 -I/opt/mozjpeg/include -I/opt/mozjpeg/lib64 -DHAVE_CONFIG_H   -c -o jpegoptim.o jpegoptim.c

gcc  -g -O2 -I/opt/mozjpeg/include -I/opt/mozjpeg/lib64 -DHAVE_CONFIG_H   -c -o jpegdest.o jpegdest.c
gcc  -g -O2 -I/opt/mozjpeg/include -I/opt/mozjpeg/lib64 -DHAVE_CONFIG_H   -c -o misc.o misc.c
gcc  -g -O2 -I/opt/mozjpeg/include -I/opt/mozjpeg/lib64 -DHAVE_CONFIG_H -o jpegoptim jpegoptim.o jpegdest.o misc.o  -L/opt/mozjpeg/lib64 -L/opt/mozjpeg/lib64 -lm -ljpeg
```

Output is:

```
ubuntu:~/scripts/jpegoptim$  /usr/local/bin/jpegoptim -V
jpegoptim v1.4.6  x86_64-unknown-linux-gnu
Copyright (C) 1996-2018, Timo Kokkonen

This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistirbute it under certain conditions.
See the GNU General Public License for more details.


libjpeg version: 6b  27-Mar-1998
Copyright (C) 1991-2018 The libjpeg-turbo Project and many others

```

@dvershinin
Copy link

@adrianmihalko the output of jpegoptim -V won't be illustrative, because libjpeg version: 6b 27-Mar-1998 will be there irrespective of using the standard library or MozJPEG.

The best way to check if you have successfully compiled MozJPEG in is with ldd /path/to/jpegoptim | grep jpeg. If the output is empty, it means the library was linked in statically.

@adrianmihalko
Copy link
Author

@adrianmihalko the output of jpegoptim -V won't be illustrative, because libjpeg version: 6b 27-Mar-1998 will be there irrespective of using the standard library or MozJPEG.

The best way to check if you have successfully compiled MozJPEG in is with ldd /path/to/jpegoptim | grep jpeg. If the output is empty, it means the library was linked in statically.

Thank you, based on this I think mozjpeg is enabled:

$ ldd /usr/local/bin/jpegoptim | grep jpeg
libjpeg.so.62 => /opt/mozjpeg/lib64/libjpeg.so.62 (0x00007f7ee9b70000)

@ozcoder
Copy link

ozcoder commented Mar 10, 2020

If you want some more detail

$ ldd /usr/local/bin/jpegoptim | grep -i jpeg | tr -d "\n" | cut -d">" -f2 | cut -d' ' -f2 | xargs -i{} strings {} | grep mozjpeg

mozjpeg version 4.0.0 (build 20191127)

@adrianmihalko
Copy link
Author

I think after 3 years I can close this issue. Thanks for tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants