⟵ Writing

Compressing all pngs in a directory with pngquant

2019-10-30

On a project I'm working on currently we've been using a lot of uncompressed png's, which is killing the pageload of nearly every section.

I didn't want to have to manually compress every file and as a result came up with a little solution using pngquant.

First find all the files in the directory you want to compress, so lets use find for this.

find src | grep '.png'

The output should look something like this.

1src/components/assets/testing/icon.png
2src/components/assets/testing/app.png
3

Now just pipe the output into xargs and run pngquant on it for each line.

find src | grep '.png' | xargs -L1 pngquant

Boom, all the files will now be compressed