![压缩给定图像的 CLI 工具,无论图像是什么类型(png、jpg、gif、webp、svg)?](https://linux22.com/image/205412/%E5%8E%8B%E7%BC%A9%E7%BB%99%E5%AE%9A%E5%9B%BE%E5%83%8F%E7%9A%84%20CLI%20%E5%B7%A5%E5%85%B7%EF%BC%8C%E6%97%A0%E8%AE%BA%E5%9B%BE%E5%83%8F%E6%98%AF%E4%BB%80%E4%B9%88%E7%B1%BB%E5%9E%8B%EF%BC%88png%E3%80%81jpg%E3%80%81gif%E3%80%81webp%E3%80%81svg%EF%BC%89%EF%BC%9F.png)
我知道有很多工具可以优化图像:
- 庞克量化
- 优化
- jpegoptim
- 动画棒
- exif工具
- 埃克
但它们都是特定于某种文件类型的。是否有一个命令行,无论传递什么图像类型,它都会应用正确的压缩?类似于什么的东西https://compressor.io但 cli 确实如此。
对于“优化”,我的意思是减小整个文件的大小,同时保持其视觉上几乎相同(感谢@Philippos)。
答案1
如果您不介意使用 SVG 作为中间格式,那么inkscape
可能会有用。
但您可能正在寻找 ImageMagick 的convert
.
从手册页:
convert-im6.q16(1) General Commands Manual convert-im6.q16(1)
NAME
convert - convert between image formats as well as resize an image,
blur, crop, despeckle, dither, draw on, flip, join, re-sample, and
much more.
SYNOPSIS
convert-im6.q16 [input-option] input-file [output-option] output-file
OVERVIEW
The convert-im6.q16 program is a member of the ImageMagick-
ims6.q16(1) suite of tools. Use it to convert between image formats
as well as resize an image, blur, crop, despeckle, dither, draw on,
flip, join, re-sample, and much more.
For more information about the convert command, point your browser to
file:///usr/share/doc/imagemagick-6-common/html/www/convert.html (on
debian system you may install the imagemagick-6 package) or
https://www.imagemagick.org/script/convert.php.
它将使用与您正在使用的文件类型相关的压缩(jpeg 的压缩方式与 png 不同)。您可以使用以下命令选择其他类型的压缩-compress
标记并指定“无”、“BZip”、“传真”、“Group4”、“JPEG”、“JPEG2000”、“无损”、“LZW”、“RLE”或“Zip”。
使用该-quality
选项设置 JPEG、PNG、MIFF 和 MPEG 编码器使用的压缩级别。使用该-sampling-factor
选项设置 JPEG、MPEG 和 YUV 编码器用于对色度通道进行下采样的采样因子。