![如何让 pngcrush 覆盖原始文件?](https://linux22.com/image/1034577/%E5%A6%82%E4%BD%95%E8%AE%A9%20pngcrush%20%E8%A6%86%E7%9B%96%E5%8E%9F%E5%A7%8B%E6%96%87%E4%BB%B6%EF%BC%9F.png)
我读过man pngcrush
,似乎没有办法压缩 PNG 文件并将其保存在原始文件上。我想压缩几个文件夹中的 PNG 文件,所以用一个命令完成所有操作会很有用!
目前我正在手动将pngcrush -q -d tmp *.png
文件从tmp
目录剪切粘贴到原始文件夹。所以我想使用mv
可能是最好的方法?还有更好的想法吗?
答案1
自 1.7.22 版本起,pngcrush
具有覆盖选项。
尝试
pngcrush -ow file.png
看更新日志了解更多信息:
Version 1.7.22 (built with libpng-1.5.6 and zlib-1.2.5)
Added "-ow" (overwrite) option. The input file is overwritten and the
output file is just used temporarily and removed after it is copied
over the input file.. If you do not specify an output file, "pngout.png"
is used as the temporary file. Caution: the temporary file must be on
the same filesystem as the input file. Contributed by a group of students
of the University of Paris who were taking the "Understanding of Programs"
course and wished to gain familiarity with an open-source program.
答案2
所有内容都在一行上:
for file in *.png; do pngcrush "$file" "${file%.png}-crushed.png" && mv "${file%.png}-crushed.png" "$file"; done
应该这么做。
(尽管到目前为止,在我自己的测试中,我测试过的 png 中只有不到一半的图像pngcrush
在之后变得更小,所以我对此并不满意。)