Multiple Image Compression Solutions for CentOS Systems
In the article Using TinyPNG to Optimize Your Website Images, the compression service provided by TinyPNG was introduced, and the results were excellent. ImgURL image hosting also uses TinyPNG to provide image compression, but TinyPNG has a limit on free usage. Therefore, xiaoz searched for other image compression solutions under the Linux system, hoping to use them later.

OptiPNG
OptiPNG is a PNG optimizer that can re-compress image files into smaller sizes without losing any information. It can also compress formats like .bmp and .gif. The installation method is as follows:
# Please ensure the EPEL repository is installed first, then install directly using yum
yum -y install optipng
# Alternatively, you can download the source code and compile it
# Download OptiPNG source code
wget -O optipng.tar.gz http://prdownloads.sourceforge.net/optipng/optipng-0.7.7.tar.gz?download
# Extract
tar -zxvf optipng.tar.gz
# Enter the directory
cd optipng-0.7.7/
# Compile and install
./configure
make && make install
If everything goes smoothly, after successful installation, you can enter optipng -V to check the current version, as shown in the screenshot below.

Directly enter the command optipng xxx.png to compress a .png image. OptiPNG has more parameters; you can enter optipng -h to view the help information.
Synopsis:
optipng [options] files ...
Files:
Image files of type: PNG, BMP, GIF, PNM or TIFF
Basic options:
-?, -h, -help show this help
-o <level> optimization level (0-7) [default: 2]
-v run in verbose mode / show copyright and version info
General options:
-backup, -keep keep a backup of the modified files
-clobber overwrite existing files
-fix enable error recovery
-force enforce writing of a new output file
-preserve preserve file attributes if possible
-quiet, -silent run in quiet mode
-simulate run in simulation mode
-out <file> write output file to <file>
-dir <directory> write output file(s) to <directory>
-log <file> log messages to <file>
-- stop option switch parsing
Optimization options:
-f <filters> PNG delta filters (0-5) [default: 0,5]
-i <type> PNG interlace type (0-1)
-zc <levels> zlib compression levels (1-9) [default: 9]
-zm <levels> zlib memory levels (1-9) [default: 8]
-zs <strategies> zlib compression strategies (0-3) [default: 0-3]
-zw <size> zlib window size (256,512,1k,2k,4k,8k,16k,32k)
-full produce a full report on IDAT (might reduce speed)
-nb no bit depth reduction
-nc no color type reduction
-np no palette reduction
-nx no reductions
-nz no IDAT recoding
Editing options:
-snip cut one image out of multi-image or animation files
-strip <objects> strip metadata objects (e.g. "all")
Optimization levels:
-o0 <=> -o1 -nx -nz (0 or 1 trials)
-o1 <=> -zc9 -zm8 -zs0 -f0 (1 trial)
(or...) -zc9 -zm8 -zs1 -f5 (1 trial)
-o2 <=> -zc9 -zm8 -zs0-3 -f0,5 (8 trials)
-o3 <=> -zc9 -zm8-9 -zs0-3 -f0,5 (16 trials)
-o4 <=> -zc9 -zm8 -zs0-3 -f0-5 (24 trials)
-o5 <=> -zc9 -zm8-9 -zs0-3 -f0-5 (48 trials)
-o6 <=> -zc1-9 -zm8 -zs0-3 -f0-5 (120 trials)
-o7 <=> -zc1-9 -zm8-9 -zs0-3 -f0-5 (240 trials)
-o7 -zm1-9 <=> -zc1-9 -zm1-9 -zs0-3 -f0-5 (1080 trials)
Notes:
The combination for -o1 is chosen heuristically.
Exhaustive combinations such as "-o7 -zm1-9" are not generally recommended.
Examples:
optipng file.png (default speed)
optipng -o5 file.png (slow)
optipng -o7 file.png (very slow)
OptiPNG homepage: http://optipng.sourceforge.net/
jpegoptim
jpegoptim is an open-source image compression tool that can only compress .jpg format. It can be installed directly using the yum command. After installation, you can enter jpegoptim -V to check the version.
yum -y install jpegoptim

Enter the command jpegoptim -m 80 xxx.jpg to compress the image. -m refers to the optimization quality, with selectable values from 0-100. The larger the value, the faster the speed and the better the quality, but the compression effect is worse. More parameters can be viewed by entering jpegoptim -h.
jpegoptim v1.4.6 Copyright (C) 1996-2018, Timo Kokkonen
Usage: jpegoptim [options] <filenames>
-d<path>, --dest=<path>
specify alternative destination directory for
optimized files (default is to overwrite originals)
-f, --force force optimization
-h, --help display this help and exit
-m<quality>, --max=<quality>
set maximum image quality factor (disables lossless
optimization mode, which is by default on)
Valid quality values: 0 - 100
-n, --noaction don't really optimize files, just print results
-S<size>, --size=<size>
Try to optimize file to given size (disables lossless
optimization mode). Target size is specified either in
kilo bytes (1 - n) or as percentage (1% - 99%)
-T<threshold>, --threshold=<threshold>
keep old file if the gain is below a threshold (%)
-b, --csv print progress info in CSV format
-o, --overwrite overwrite target file even if it exists (meaningful
only when used with -d, --dest option)
-p, --preserve preserve file timestamps
-P, --preserve-perms
preserve original file permissions by overwriting it
-q, --quiet quiet mode
-t, --totals print totals after processing all files
-v, --verbose enable verbose mode (positively chatty)
-V, --version print program version
-s, --strip-all strip all markers from output file
--strip-none do not strip any markers
--strip-com strip Comment markers from output file
--strip-exif strip Exif markers from output file
--strip-iptc strip IPTC/Photoshop (APP13) markers from output file
--strip-icc strip ICC profile markers from output file
--strip-xmp strip XMP markers markers from output file
--all-normal force all output files to be non-progressive
--all-progressive force all output files to be progressive
--stdout send output to standard output (instead of a file)
--stdin read input from standard input (instead of a file)
jpegoptim project address: https://github.com/tjko/jpegoptim
Google WebP
WebP is a modern image format that provides excellent lossless and lossy compression for images on the web. Using WebP, website administrators and web developers can create smaller, richer images, making the web faster.
CentOS can use yum to install:
yum -y install libwebp-devel libwebp-tools
Use the cwebp command line to convert PNG or JPEG image files to WebP format. You can use the following command to convert a PNG image file to a WebP image with a quality range of 80:
cwebp -q 80 image.png -o image.webp
For more information on WebP usage, please refer to the Google official documentation: new image format for the Web. By the way, the domestic Upyun CDN already supports automatically converting images to WebP format.
Summary
No matter which image compression solution is used, it is impossible to achieve 100% lossless compression; the goal is to reduce image volume as much as possible without significantly reducing image quality. It is recommended that you appropriately compress website images to improve website speed. If you have better compression solutions, please leave a message to recommend them.