8

I have a stack of hundreds of pictures and i want to use pngcrush for reducing the file sizes.

I know how to crush one file with terminal, but all over the web i find parts of explanations that assume previous knowledge.

can someone please explain how to do it clearly.

Thanks Shani

shannoga
  • 19,649
  • 20
  • 104
  • 169

4 Answers4

8

You can use following script:

#!/bin/bash

# uncomment following line for more aggressive but longer compression
# pngcrush_options=-reduce -brute -l9
find . -name '*.png' -print | while read f; do
  pngcrush $pngcrush_options -e '.pngcrushed' "$f"
  mv "$f" "${f/%.pngcrushed/}"
done
Andrey Starodubtsev
  • 5,139
  • 3
  • 32
  • 46
1

Current versions of pngcrush support this functionality out of the box.

( I am using pngcrush 1.7.81)

pngcrush -dir outputFolder inputFolder/*.png

will create "outputFolder" if it does not exist and process all the .png files in the "inputFolder" placing them in "outputFolder".

Obviously you can add other options e.g.

pngcrush -dir outputFolder -reduce -brute -l9 inputFolder/*.png

rob
  • 8,134
  • 8
  • 58
  • 68
0

Being in 2023, there are better tools to optimize png images like OptiPNG

    • install
sudo apt-get install optipng
    • use for one picture
optipng imagen.png
    • use for all pictures in folder
find /path/to/files/ -name '*.png' -exec optipng -o7 {} \;

optionally the command -o defines the quality, being possible from 1 to 7, where 7 is the maximum compression level of the image.

-o7
Ale DC
  • 1,646
  • 13
  • 20
-1

The high rated fix appears dangerous to me; it started compressing all png files in my iMac; needed is a command restricted to a specified directory; I am no UNIX expert; I undid the new files by searching for all files ending in .pngcrushed and deleting them