How to use jpegoptim to compress pictures under Linux
Editor to share with you how to use jpegoptim to compress pictures under Linux. I hope you will get something after reading this article. Let's discuss it together.
Jpegoptim is a tool for optimizing JPEG files, providing lossless optimization (based on Huffman tables), while also setting quality factors for lossy optimization.
Install jpegoptim
Ubuntu, Debian or Linux Mint:
$sudo apt-get install jpegoptim
Fedora:
$sudo yum install jpegoptim
To install CentOS/RHEL, open the EPEL library first, and then run the following command:
$sudo yum install jpegoptim
Lossless compression of jpeg images
To compress a JPG image losslessly, use:
$jpegoptim photo.jpg
Photo.jpg 2048 × 1536 24bit N ICC JFIF [OK] 882178-"821064 bytes (6.93%), optimized.
Note that the original image will be overwritten by the compressed image.
If jpegoptim does not beautify the image losslessly, it will not be overwritten:
$jpegoptim-v photo.jpg
Photo.jpg 2048 × 1536 24bit N ICC JFIF [OK] 821064-"821064 bytes (0.005%), skipped.
If you want to protect the original picture, use the "- d" parameter to specify the save directory
$jpegoptim-d. / compressed photo.jpg
In this way, the compressed picture will be saved in. / compressed directory (with the same input file name)
If you want to protect the creation modification time of the file, use the "- p" parameter. In this way, the compressed image will get the same date and time as the original picture.
$jpegoptim-d. / compressed-p photo.jpg
If you just want to look at lossless compression ratios rather than really want to compress them, use the "- n" parameter to simulate compression, and then it will show the compression ratio.
$jpegoptim-n photo.jpg
Lossy compression of JPG image
In case you really need to save it in the cloud space, you can also use lossy compression of JPG images.
In this case, use the "- m" quality option, which ranges from 0 to 100. (0 is the best quality, 100 is the worst quality)
For example, compress a picture with 50% quality:
$jpegoptim-m50 photo.jpg
Photo.jpg 2048 × 1536 24bit N ICC JFIF [OK] 882178-"301780 bytes (65.79%)
Optimized.
At the expense of quality, you will get a smaller picture.
Compress multiple JPEG images at once
The most common case is the need to compress multiple JPEG image files in a directory. To deal with this situation, you can use the following script.
#! / bin/sh
# compress all * .jpg files in the current directory
# Save in. / compressed directory
# and have the same modification date as the original file
For i in * .jpg; do jpegoptim-d. / compressed-p "$I"; done
After reading this article, I believe you have a certain understanding of "how to use jpegoptim to compress pictures under Linux". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!