In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "Linux system how to compress JPEG images on the command line", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to compress JPEG images in the command line under the Linux system"!
Nowadays, photo devices (such as smartphones and digital cameras) take pictures with higher and higher resolution. Even the 36.3 million-pixel Nikon D800 has entered the market, and the trend can't stop. Today's photo equipment is constantly improving the resolution of photos, so that we have to compress it and upload it to a cloud with storage and bandwidth restrictions.
In fact, there is a very simple way to compress JPEG images. A command-line tool called "jpegoptim" can help you beautify JPEG images "losslessly" so that you can compress JPEG images without sacrificing their quality. In case your storage space and bandwidth budget is really small, jpegoptim also supports "lossy" compression to resize images.
If you want to compress PNG images, refer to the example in this guide.
Install jpegoptim
Ubuntu, Debian or Linux Mint:
The code is as follows:
$sudo apt-get install jpegoptim
Fedora:
The code is as follows:
$sudo yum install jpegoptim
To install CentOS/RHEL, open the EPEL library first, and then run the following command:
The code is as follows:
$sudo yum install jpegoptim
Lossless compression of jpeg images
To compress a JPG image losslessly, use:
The code is as follows:
$jpegoptim photo.jpg
Photo.jpg 2048x1536 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:
The code is as follows:
$jpegoptim-v photo.jpg
Photo.jpg 2048x1536 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
The code is as follows:
$jpegoptim-d. / compressed photo.jpg
In this way, the compressed picture will be saved in the. / 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.
The code is as follows:
$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.
The code is as follows:
$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, the "- m" option is used and the number of masses ranges from 0 to 100. (0 is the best quality, 100 is the worst quality)
For example, compress a picture with 50% quality:
The code is as follows:
$jpegoptim-m50 photo.jpg
Photo.jpg 2048x1536 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.
The code is as follows:
#! / bin/sh
# compress all * .jpg files in the current directory
# saved in. / compressed directory
# and have the same modification date as the original file
For i in * .jpg; do jpegoptim-d. / compressed-p "$I"; done
Thank you for reading, these are the contents of "how to compress JPEG images on the command line under the Linux system". After the study of this article, I believe you have a deeper understanding of how to compress JPEG images on the command line under the Linux system. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.