Linux:Jpeg 图像优化/压缩命令
我知道如何使用 optipng 命令 . 行工具优化和压缩 png 图像。我有很多 JPEG 格式的图像。如何在我的亚马逊云帐户上压缩和优化 JPEG 图像,以便节省 cloudfront cdn 帐户上的带宽?如何使用图像压缩器对 JPEG 文件进行无损压缩,而不会影响使用 Linux 批量处理的图像质量?
对于高分辨率照片风格图像,建议使用 JPG 文件格式。您需要使用 jpegoptim 命令。它用于优化/压缩 jpeg 文件。程序支持无损优化,该优化基于优化 Huffman 表。还有所谓的“有损”优化,除了优化 Huffman 表之外,用户还可以指定图像质量的上限。
教程详细信息 | |
---|---|
难度等级 | 简单的 |
Root 权限 | 是的 |
要求 | jpegoptim |
预计阅读时间 | 3 分钟 |
安装
键入以下命令:
$ apt-get install jpegoptim
示例输出:
[sudo] password for vivek: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libavutil-extra-51 libggiwmh0-target-x libggi2 libgii1 libvo-aacenc0 libgii1-target-x mplayer-skin-blue libggiwmh0 libggi-target-x libvo-amrwbenc0 Use 'apt-get autoremove' to remove them. The following NEW packages will be installed: jpegoptim 0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded. Need to get 14.0 kB of archives. After this operation, 77.8 kB of additional disk space will be used. Get:1 http://mirror.anl.gov/debian/ squeeze/main jpegoptim amd64 1.2.3-2+b1 [14.0 kB] Fetched 14.0 kB in 1s (11.2 kB/s) Selecting previously deselected package jpegoptim. (Reading database ... 333683 files and directories currently installed.) Unpacking jpegoptim (from .../jpegoptim_1.2.3-2+b1_amd64.deb) ... Processing triggers for man-db ... Setting up jpegoptim (1.2.3-2+b1) ...
示例
语法是:
jpegoptim file.jpeg jpegoptim [options] file.jpeg
键入以下命令来优化 photo.jpeg,输入:
$ jpegoptim photo.jpeg
示例输出:
photo.jpeg 1312x948 24bit JFIF [OK] 25226 --> 10744 bytes (57.41%), optimized.
如何批量处理文件?
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.
参考
- jpegoptim主页。
- 参见手册页 –