Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to compress and optimize jpg and png images under Linux

Shulou Source: shulou.com Published: 2022-06-01 15:18:32 10月03日 Update

This article mainly introduces "how to compress and optimize jpg and png pictures under Linux". In daily operation, I believe many people have doubts about how to compress and optimize jpg and png pictures under Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to compress and optimize jpg and png pictures under Linux". Next, please follow the editor to study!

Jpegotim compressed jpg Picture

Install jpegotim

If you have an epel yum source, use the following command

The code is as follows:

# yum install jpegoptim

Compress picture command

The code is as follows:

# jpegoptim ttlsa.jpg

Ttlsa.jpg 1425x823 24bit N JFIF [OK] 1074449-> 853514 bytes (20.56%), optimized.

You can see that ttlsa.jpg is automatically compressed by 20.56%.

Compress it again.

The code is as follows:

# jpegoptim ttlsa.jpg

Ttlsa.jpg 1425x823 24bit N JFIF [OK] 853514-> 853514 bytes (0.005%), skipped.

The picture has already been compressed, so the prompt is skipped and does not need to be compressed again.

Provide a batch compressed script

The code is as follows:

For i in / data/site/image.ttlsa.com/images/*.jpg; do jpegoptim $I; done

Pngcrush optimized PNG Picture

Project address: http://pmt.sourceforge.net/pngcrush/

The code is as follows:

# wget http://downloads.sourceforge.net/project/pmt/pngcrush/1.7.88/pngcrush-1.7.88.tar.gz

# tar-xzvf pngcrush-1.7.88.tar.gz

# cd pngcrush-1.7.88

# make

# cp pngcrush / usr/bin

Pngcrush uses syntax

The code is as follows:

Usage: pngcrush [options except for-e-d] infile.png outfile.png

Pngcrush-e ext [other options] file.png...

Pngcrush-d dir/ [other options] file.png...

Pngcrush-ow [other options] file.png [tempfile.png]

Pngcrush-n-v file.png...

Options:

-bail (bail out of trial when size exceeds best size found

-bit_depth depth (deprecated)

-blacken (zero samples underlying fully-transparent pixels)

-brute (use brute-force: try 148different methods)

. For more information, please read for help.

Pngcrush simple command

The code is as follows:

Pngcrush-brute-e "myimage_compressed.png" myimage.png

. Omit.

Best pngcrush method = 123 (ws 15 fm 4 zl 9 zs 1) = 124820

For output to ttlsattlsa_new.png

(1.63% critical chunk reduction)

(1.63% filesize reduction)

CPU time decoding 1.560, encoding 7.640, other 0.030, total 9.230 sec.

Batch optimization of PNG pictures

The code is as follows:

Pngcrush-brute-d "/ data/site/image.ttlsa.com/images" * .png

At this point, the study on "how to compress and optimize jpg and png images under Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Pictures code learning commands more help practical next content address article method theory knowledge article website script grammar material follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia macOS Linux Redmi