Recursively batch process files with pngquant

前端 未结 2 1394
[愿得一人]
[愿得一人] 2020-12-13 00:49

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

相关标签:
2条回答
  • 2020-12-13 01:03

    With the fish shell you can run the following from the root of your project directory

    pngquant **.png
    

    Which will generate new files with extensions like -or8.png or -fs8.png.

    If you want to overwrite the existing files, you can use

    pngquant **.png --ext .png --force
    
    0 讨论(0)
  • 2020-12-13 01:20

    If you have limited depth of directories and not too many files, then lazy solution:

    pngquant *.png */*.png */*/*.png
    

    A standard solution:

    find . -name '*.png' -exec pngquant --ext .png --force 256 {} \;
    

    and multi-core version:

    find . -name '*.png' -print0 | xargs -0 -P8 -L1 pngquant --ext .png --force 256
    

    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).

    0 讨论(0)
提交回复
热议问题