Publish: 2018-11-17 | Modify: 2018-11-17
The previous article "Multiple image compression solutions under CentOS" shared three different compression solutions, and in this article, an additional open-source project called mozjpeg from Mozilla will be added, which can effectively compress JPEG
images.
Source code download link: https://github.com/mozilla/mozjpeg/releases
# Install nasm environment
yum -y install build-essential nasm
# Download source code
wget https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz
# Unzip
tar -zxvf v3.3.1.tar.gz
# Enter the directory
cd mozjpeg-3.3.1
autoreconf -fiv
# Compile and install
./configure
make && make install
After successful installation, the binary files are located in the /opt/mozjpeg/bin
directory and can be directly copied to the /usr/bin
directory for direct use. The cjpeg
is mainly used for image compression. Enter the following command to copy:
[root@aliyun-sgp ~]# ll /opt/mozjpeg/bin
total 256
-rwxr-xr-x 1 root root 56816 Nov 16 13:42 cjpeg
-rwxr-xr-x 1 root root 45864 Nov 16 13:42 djpeg
-rwxr-xr-x 1 root root 53504 Nov 16 13:42 jpegtran
-rwxr-xr-x 1 root root 13624 Nov 16 13:42 rdjpgcom
-rwxr-xr-x 1 root root 64592 Nov 16 13:42 tjbench
-rwxr-xr-x 1 root root 13624 Nov 16 13:42 wrjpgcom
[root@aliyun-sgp ~]# cp /opt/mozjpeg/bin/cjpeg /usr/bin/
Mozilla JPEG only supports compressing JPEG
images. The compression command is as follows:
cjpeg -quality 80 xxx.jpg > xxx_1.jpg
# or
cjpeg -outfile xxx_1.jpg -quality 80 xxx.jpg
The above command means compressing xxx.jpg
and save the compressed file as xxx_1.jpg
with a compression quality of 80.
-quality
: Specifies the compression quality (0-100). If not specified, the default is 75. The larger the value, the faster the efficiency, but the worse the compression quality. It is recommended to keep the default value.-outfile
: Save the compressed image as a new file, or use the redirection symbol >
.I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.