问题描述
我有很多想用pngquant处理的图像。它们以非常深的目录结构组织,因此在每个目录中手动 cd
并运行 pngquant -ext .png非常耗时 - force 256 * .png
I have a lot of images that I would like to process with pngquant. They are organized in a pretty deep directory structure, so it is very time-consuming to manually cd
into every directory and run pngquant -ext .png -force 256 *.png
有没有办法让这个命令在当前目录中的每个目录中的每个* .png上运行,根据需要尽可能多的层?
Is there a way to get this command to run on every *.png in every directory within the current one, as many layers deep as necessary?
推荐答案
如果目录深度有限且文件太多,那么懒惰解决方案:
If you have limited depth of directories and not too many files, then lazy solution:
pngquant *.png */*.png */*/*.png
标准解决方案:
find . -name '*.png' -exec pngquant --ext .png --force 256 {} \;
和多核版本:
find . -name '*.png' -print0 | xargs -0 -P8 -L1 pngquant --ext .png --force 256
其中 -P8
定义CPU数量, -L1
定义一个pngquant调用中要处理的图像数量(我使用 -L4
用于在流程开始时保存大量小图片的文件夹。
where -P8
defines number of CPUs, and -L1
defines a number of images to process in one pngquant call (I use -L4
for folders with a lot of small images to save on process start).
这篇关于使用pngquant递归批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!