如何获取pngcrush覆盖原始文件?


15

我已通读man pngcrush,似乎没有办法粉碎PNG文件并将其保存为原始文件。我想压缩几个价值PNG的文件夹,因此用一个命令完成所有操作将很有用!

目前,我正在pngcrush -q -d tmp *.png手动将文件从tmp目录中剪切粘贴到原始文件夹中。所以我猜mv可能是最好的选择吗?还有更好的主意吗?

Answers:


17

全部一行:

for file in *.png; do pngcrush "$file" "${file%.png}-crushed.png" && mv "${file%.png}-crushed.png" "$file"; done

应该这样做。

(尽管到目前为止,在我自己的测试中,事后我测试的png不到一半pngcrush都变小了,所以给我留下深刻的印象。)


谢谢!您可以压缩PNG的数量取决于它们的制作方式。我相信Photoshop的“另存为Web”具有某种内置的PNG破碎机
。– DisgruntledGoat

我的大多数是使用ImageMagick的import命令创建的。我尽可能避免使用Photoshop等商业软件。
frabjous

4
使用-brute可获得更好的压缩效果。
Collin Anderson 2012年

1
对方的回答是,现在有新的pngcrush更好。
雨果

22

从1.7.22版开始,pngcrush具有覆盖选项。

尝试

pngcrush -ow file.png

有关更多信息,请参见Changelog

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.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.