Can someone please explain clearly how to use "pngcrush" for multiply items
Asked Answered
P

4

9

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

Podvin answered 22/6, 2011 at 10:8 Comment(0)
C
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
Crofoot answered 24/2, 2012 at 20:46 Comment(0)
P
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

Pelagia answered 29/3, 2015 at 13:47 Comment(0)
C
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
Crossruff answered 17/1, 2023 at 18:24 Comment(0)
R
-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

Rustproof answered 23/6, 2019 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.