Reduce PNG Graphic Size Using PNGCRUSH

By  on  

Now that I'm knee-deep in MacBook I love working with command line applications. There's a certain beauty in the simplicity of using the console instead of a nice GUI. One task I use the console for often is reducing the size of PNG files using the powerhouse that is PNGCRUSH.

The Shell Script

# directive
pngcrush -reduce -brute source.png destination.png

Best pngcrush method = 113 (fm 0 zl 9 zs 0) for destination.png
     (33.38% IDAT reduction)
     (33.43% filesize reduction)

   CPU time used = 835.707 seconds (decoding 151.450,
          encoding 679.145, other 5.112 seconds)

The above directive is a basic usage of PNGCRUSH. PNGCRUSH offers a wealth of options that allow you to optimize your PNGs. If you use many PNGs on your website, optimizing them using PNGCRUSH is a must. Using the above directive, PNGCRUSH took a 11.7MB down to 7.8MB. NO QUALITY LOSS. Sure it took over 10 minutes, but think of the bandwidth your site will save.

Recent Features

  • By
    Animated 3D Flipping Menu with CSS

    CSS animations aren't just for basic fades or sliding elements anymore -- CSS animations are capable of much more.  I've showed you how you can create an exploding logo (applied with JavaScript, but all animation is CSS), an animated Photo Stack, a sweet...

  • By
    Welcome to My New Office

    My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...

Incredible Demos

  • By
    JavaScript Speech Recognition

    Speech recognition software is becoming more and more important; it started (for me) with Siri on iOS, then Amazon's Echo, then my new Apple TV, and so on.  Speech recognition is so useful for not just us tech superstars but for people who either want to work "hands...

  • By
    Using MooTools For Opacity

    Although it's possible to achieve opacity using CSS, the hacks involved aren't pretty. If you're using the MooTools JavaScript library, opacity is as easy as using an element's "set" method. The following MooTools snippet takes every image with the "opacity" class and sets...


  1. no way dude, I suggest u 2 give a try to image magick
    that looks a little bit powerful & faster and gives u the same or better results

    when I need to shrink down images in some app I always use this
    it’s capable to manage even other formats such as jpg, gif etc..

    • Could you elaborate on how image-magick can compress PNGs? I can’t seem to see anything in the documentation on how to do it. It is an amazingly powerful program, so I am sure I am missing something.

  2. Fabian
  3. I’ve always loved PNG’s – and I’ve been impressed with the file sizes that Fireworks and Photoshop can output. But thx to this heads up David it looks like I’ll be squeezing a little bit more out of my PNG’s from now on.


    And apparently the above is spammy and I have to try again… what algorithm are you using? I have no links… It’s a pretty straight up comment…

  4. I’ve used that proggy in the past and it gave me same results as photoshop pics.
    Whenever I’ll need to try something more than imagemagick, I’ll give it a try…

  5. And if anyone doesn’t want to install pngcrush or mess with terminal, they can use this dashboard app which does the same thing:
    You just drop the image onto it
    I did a quick test with pngcrush/terminal and pngpong – result was the same

  6. Simon is indeed a very good compression tool, but sometimes tools like pngcrush or optipng do a better job.
    I use optipng and it’s damn good ! Yes it’s slow but it works really great. On Windows (yes I know, shame on me :p ) I use a .bat file with this in it:
    “PathTo\optipng.exe” -o7 %1
    Drag & drop and you’re done :)

  7. I’ll do a follow up post where I try all of these methods and see which does the best job. Good suggestions everyone!

  8. i like pngout with .cmd file:

    for /F “delims=” %%S in (‘dir /S /A-D /B *.png’) do @pngout “%%~S”

    with recursive file scan in subdirs :D

  9. James Parsons

    I prefer as well. It uses several compression methods to get the smallest possible file size without losing any quality. The difference between and pngout/pngcrush is ~0.1KB from my tests, and is more efficient.

  10. Anton


    I’ve tried both scripts, PNGCRUSH and IMAGEMAGICK on a 330kb ‘photobooth’ photo and PNGCRUSH was ultimately better:
    PNGCRUSH = 260kb
    IMAGEMAGICK = 276kb

  11. In your comparison make sure to compare “Save for Web” in photoshop. I’m curious to see how it stacks up.

    I’ve been using macs for over 10 years now and I’m still terminal averse.

  12. @Ryan Florence,

    I have compressed images with png crush over 90% of that of Adobe’s “Save for Web”.


    Checkout jpegtran for Jpegs. Also, imagemagic is awesome but I usually use it for a different purpose. For example, image magick can tell you how many colors your image has and you can adjust your png accordingly. Compressing a 24bit png with pngcrush is worthless when you only use 8 colors in your image.

  13. Gracepoint After Five just recently launched punypng ( which combines a lot of the open-source technologies out there. The User Experience team that I’m a part of uses punypng as our weapon of choice as well as the Gracepoint Fellowship Church web team. It’s very competitive to and pngout, and punypng beats them out most of the time (though don’t my word for it, try it out yourself to see).

    I think the great thing about something like punypng versus the command-line tools is that you can throw a whole folder at punypng and just let punypng do all the work to figure out which tool is best for the job. Sometimes converting a JPEG to PNG and then compressing it down is better … sometimes jpeg-tran or jpegoptim is better. Punypng just works.

    For more info about punypng on the Gracepoint After Five blog:

  14. DivaWebDzgn

    This is why I always say, you NEVER stop learning.. I thought I “got it” when it came to graphics optimization.. Been Googling my but off and found out that there’s a whole WORLD of information I didn’t know about.. Especially when it comes to my beloved PNGs.. LOL Good article!

    I’ll be watching this blog for the follow-up article.. I’m curious as to how stacks up.. I’m a lot like Ryan.. I’m not necessarily terminal adverse, but after years of Macs and WIndows machines, I just prefer a GUI app over command line app.. :)

  15. This is great, but, what about Windows users?

  16. Hassan: Grab Cygwin and install PNGCRUSH on that. Or you could just use Smush.It.

  17. Paul de Vries

    I tried PNGCursh and on an uncompressed PNG of 93Kb.

    PNGChrush: 90Kb 87,32Kb
    PS Save for web: 87,06Kb

    I used the following command line for pngcrush: pngcrush.exe -reduce -brute -e 2.png “%1”

    Maybe I am doing something wrong?

  18. @paul: Try

  19. I did a comparison of 8 free image optimizer tools, the post is in Spanish but the comparison chart is very easy to understand.

  20. So… there a way for non-command line folks to do this via a drag / drop app?

  21. @David Walsh: pngcrush works just fine on Windows too.

  22. @jay: Acorn on the Mac uses pngcrush when you save a png for the web.

  23. Greg ONeill

    Not sure if it’s because of a mac or something but I don’t think it should take 10 minutes. On my windows machine the operation was almost instant.

  24. Otamay

    A little late (half year xD).

    The script is very useful for using pngcrush. I’m using it to reduce the size of hi resolution zelda images. Yeah!

    But I’ve had problems with file names containing spaces. This little modification can do the trick.

    find $1 -name "*.png" | while read png
    echo "crushing $png"
    pngcrush -brute "$png" /tmp/temp.png
    mv -f /tmp/temp.png "$png"

  25. Tarik

    I use and it is kind of cool enough for me. :)

  26. A nice idea for handling a lot of PNG in the context of website development would be to dynamically separate the image data from the alpha channel on the server, optimize both of them separately and recombine them using the canvas element and some JavaScript in the browser. Ta-Da! Works with all modern browsers.

    Here is explained how it’s done:

    You’ll also find a complete ZIP package with the PHP script and a jQuery plugin. Let us know what you think about this.

  27. What about

    Has anyone tried it.

  28. Tom

    @parvez, works wonders.. PNGCrush & could reduce my image down to 23KB from 25, PunyPNG offered savings up to 16KB with lossy compression if I upgraded to their ‘pro plan’, however TinyPNG brought it down to 8KB with lossy compression and it’s a free service. It preserved full alpha transparency and my eyes cannot spot a single difference from the original. Thanks for the recommendation, using this site from now on and donating soon.

  29. Tom

    I would like to add that Yahoo’s “” is great for losslessly reducing images, e.g. JPEG ;)

  30. ddd

    I can recommend this service:

    They strip off meta data but too compress the image data as well. purists may complain, but the results are very good, in deed, for file size and image quality…

    Source Image/No Alpha/24-Bit PNG (401,9 KB):

    216,3 KB with
    375,7 KB with PNGpong
    381,3 KB with Yahoo

    @Conrad Chu:
    Your service isnt free for image sizes above 150KB :-( You are inventor of this software and also running this paid service. So I have to consider your comment here to be spam?

  31. I can recommend this service:

    They strip off meta data but too compress the image data as well. purists may complain, but the results are very good, in deed, for file size and image quality…

    Source Image/No Alpha/24-Bit PNG (401,9 KB):

    216,3 KB with
    359,5 KB with pngCrush (ImageOptim, OS X-GUI for pngCrush)
    375,7 KB with PNGpong
    381,3 KB with Yahoo

    @Conrad Chu:
    Your service isnt free for image sizes above 150KB :-( You are inventor of this software and also running this paid service. So I have to consider your comment here to be spam?

    PS: Why cant I post a comment here? No feedback on user action??!

  32. Pol

    It’s much better than tinypng.

  33. Tom

    Hey guys, TinyPNG uses which has a GUI port for windows called PNGoo.
    Also check out for any lossless optimization.

  34. copyhold

    I must say that GIMP beats them all. At least on small images (like those that you convert to datauri)
    photoshop gave me 900 byte
    imagemagik – 300
    pngcrush -300
    GIMP – ….. 120!!!!

    just do
    $gimp 1.png
    ALT-f w CTRL-Q

  35. d

    another vote for

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!