Linux:Jpeg图片优化/压缩命令

时间:2020-01-09 10:41:41  来源:igfitidea点击:

我知道如何使用optipng命令优化和压缩png图片。
但我有很多JPEG格式的图片。
如何压缩和优化亚马逊云帐户上的JPEG图片,以便节省Cloudfront CDN帐户上的带宽?
如何使用图片压缩器在JPEG文件上创建无损压缩,而使用Linux则不影响批量图片质量?

对于高分辨率的照片风格图片,建议使用JPG文件格式。
您需要使用jpegoptim命令。
它用于优化/压缩jpeg文件。
程序支持无损优化,该优化基于优化霍夫曼表。
所谓的有损优化,除了优化霍夫曼表之外,用户还可以指定图片质量的上限。

安装jpegoptim

执行以下命令:

$ apt-get install jpegoptim

例子

语法为:

jpegoptim file.jpeg
jpegoptim [options] file.jpeg

执行以下命令以优化photo.jpeg,执行:

$ jpegoptim photo.jpeg

输出示例:

photo.jpeg 1312x948 24bit JFIF  [OK] 25226 --> 10744 bytes (57.41%), optimized.

如何批量处理文件?

使用bash for loop如下:

for i in one.jpeg two.jpeg foo.jpeg; do jpegoptim "$i"; done

或者

## process all *.jpeg in the current directory 
for i in *.jpeg; do jpegoptim "$i"; done

选项

-d, --dest=
             Sets  alternative  destination  directory  where  to save optimized files (default is to overwrite the originals). Please note that unchanged
             files won't be added to the destination directory. This means if the source file can't be compressed, no file will be created in the destina‐
             tion path.

       -f, --force
             Force optimization, even if the result would be larger than the original file.

       -h, --help
             Displays short usage information and exits.

       -m[0..100], --max=[0..100]
             Sets  the maximum image quality factor (disables lossless optimization mode, which is by default enabled). This option will reduce quality of
             those source files that were saved using higher quality setting.  While files that already have lower  quality  setting  will  be  compressed
             using the lossless optimization method.

       -n, --noaction
             Don't really optimize files, just print results.

       -o, --overwrite
             Overwrite target file even if it exists (when using -d option).

       -p, --preserve
             Preserve file modification times.
       -q, --quiet
             Quiet mode.

       -t, --totals
             Print totals after processing all files.

       -v, --verbose
             Enables verbose mode (positively chatty).

       --strip-all
             Strip all (Comment & Exif) markers from output file. (NOTE! by default only Comment & Exif markers are kept, everything else is discarded)

       --strip-com
             Strip Comment (COM) markers from output file.

       --strip-exif
             Strip EXIF markers from output file.

       --strip-iptc
             Strip IPTC markers from output file.

       --strip-icc
             Strip ICC profiles from output file.