5-Minute PNG Image Optimization

by Jeff Starr on Sunday, May 17, 2009 56 Responses

A great way to improve the performance of your site is to optimize the size of your images. Smaller image sizes require less bandwidth, disk space and load time, and ultimately improve visitor experience. In this article, I share my effective 5-minute technique for optimizing PNG images. This is a two-step, lossless optimization process that removes as much extraneous data as possible without sacrificing any image quality whatsoever. It’s fast, free, and highly effective.

Step 1: Optimize with OptiPNG or Pngcrush

For the first (and most important) step in our image-optimization process, we want to run our PNG images through a command-line optimizer like OptiPNG or Pngcrush. Either of these powerful programs will remove unnecessary data from your PNG images without reducing image quality. Both are excellent programs that work beautifully. Here are the commands that I use to optimize my images with either OptiPNG or Pngcrush.

PNGcrush
If you decide to use Pngcrush, try this command for great results:

pngcrush -rem allb -brute -reduce original.png optimized.png

Quick break down of the different parameters:

  • pngcrush — run the pngcrush program 1
  • -rem allb — remove all extraneous data 2
  • -brute — attempt all optimization methods 3
  • -reduce — eliminate unused colors and reduce bit-depth 4
  • original.png — the name of the original (unoptimized) PNG file
  • optimized.png — the name of the new, optimized PNG file

OptiPNG
If you decide to use OptiPNG, throw down with this fine command:

optipng -o7 original.png

OptiPNG is very straightforward (and very effective):

  • optipng — run the optipng program 5
  • -o7 — optimize the image at the highest possible level 6
  • original.png — the name of the PNG file to be optimized

Or, to batch process an entire directory of PNG images, use this:

optipng -o7 *.png

Important note: to keep a backup of the modified files, include the -k parameter before the file name within the execution command. Just in case!

Step 2: Optimize with Smush.it

Now that you have stripped out all the extraneous data from your PNGs, it’s time to smush ‘em even more with the powerful Smush.it online optimizer. It’s so easy. Simply click on the “Uploader” tab, upload your images, and let Smush.it do its thing. Smush.it optimizes your images on the fly and even returns a summary of the saved bytes and percentages. I always get a sh.it-eating grin on my face whenever I use this excellent service. ;)

[ Screenshot: Smush.it Online Optimizer ]
Click image for details

And that’s all there is to it! Once you are done uploading your images to Smush.it, download the provided zip file and compare your optimized file sizes with those of your original images. If all goes well, you should enjoy anywhere from a 5% to 30% (or more) reduction in size, depending on the complexity and size of your images. And best of all, this fast, free and effective technique is completely lossless, meaning that your images suffer absolutely no loss of quality. Nice :)

Notes

  • 1 Using the specified parameters
  • 2 Except transparency and gamma; to remove everything except transparency, try -rem alla
  • 3 Requires more processing time and may not improve optimization by much
  • 4 If possible
  • 5 Using the specified parameters
  • 6 Requires more processing time and may not improve optimization by much; optimization levels range from 0 - 7, with 7 being the most intensive

About the author

[ Jeff Starr ]

Jeff Starr is a web developer, graphic designer and content producer with over 10 years of experience and a passion for quality and detail. Jeff is co-author of the book Digging into WordPress and strives to help people be the best they can be on the Web. + Follow Jeff on Twitter and subscribe to Perishable Press for quality web-design content delivered fresh.


56 Responses

Add a comment

[ Gravatar Icon ]

Louis#1

I think it’s worth mentioning that Smush.it has been integrated into Yslow :)

[ Gravatar Icon ]

Patternhead#2

Excellent article Jeff. I must admit that I normally just “save for web” in Photoshop and haven’t tried OptiPNG or Pngcrush. I’ll give them a try on my next project though :)

[ Gravatar Icon ]

Louis#3

Oh also, on the mac, there’s Ping which is basically an interface for OptiPNG. Here’s the description from the developper:

Unlike similar utilities, Ping is a Universal Binary. Not only that, but we’ve optimized OptiPNG (the underlying tech. that powers Ping) for the latest Intel chips — taking advantage of all the cool (at least to us geeks) features that’re at the heart of Apple’s latest and greatest computers.

I found that Photoshop provides extreme compression for JPG, but not for PNG. Ping comes in handy there.

[ Gravatar Icon ]

Jessi Hance#4

Thanks! I’ve been using smush.it but didn’t know about the other programs. Do you think it makes a difference whether you smush.it after or before the other optimizations?

[ Gravatar Icon ]

Austin Dworaczyk Wiltshire#5

In all honesty, through some of my own tests, I have found that PNGOUT provides a better size reduction then both OptiPNG or pngcrush. It also has a nice plugin for Irfanview.

[ Gravatar Icon ]

Louis#6

@Jessi: I think that Smush.it is a convenient solution for people who do not want to spend extra time optimizing, but want performance. If you want to have the best results, you should tune each and every image by hand, using Photoshop, and then other tools.

Smush.it is like brute force. It takes all the images and processes them. It works but do not provide the fine tuning you get by hand.

[ Gravatar Icon ]

Jessi Hance#7

Thanks Louis, nice to know that the pros can do it even better. Since I don’t even do image editing myself and have never owned or used Photoshop, I’ll keep using smush.it, and one of the other programs mentioned here, on the images I’ve been provided.

I don’t know why, but every time I post here, seems like someone is telling me I’m not doing things right! I really appreciate the article.

[ Gravatar Icon ]

Louis#8

@Austin: I’d love to see the numbers, and the graphs that confirm you results!

@Jessi: Smash.it does a hell of a job for most people. The two cases where it doesn’t fit are (a) you are perfectionnist and want fine tunning, and (b) you need to have a tool that optimize your images on-the-fly, server-side. You do not want to depend on a tird-party solution there.

[ Gravatar Icon ]

Jessi Hance#9

@louis: Whatever. I don’t know why you chose to address me when you said the methods in this article weren’t good enough for perfectionists. I never said I was one. Please leave me out of it.

My first comment was mostly intended to communicate my appreciation to the article’s author. (I will find out the answer to my question with my own experimentation.) Jeff, please keep doing what you do. Your articles are terrific!

[ Gravatar Icon ]

Louis#10

@Jessi: when I first read your answer to my comment, I missed this line:

I don’t know why, but every time I post here, seems like someone is telling me I’m not doing things right!

I didn’t realize I had offended you. It has never been my intention to be aggressive with you. I like to think that this place is for sharing knowledge, and since you didn’t seem familiar with image optimization, I though I would write a little about the different solutions I know, and what I think about them. I tried to be descriptive/factual but obviously I failed, and you thought I was being contemptuous.

So, again, sorry for that misunderstanding. I was only trying to be helpful here Jessi.

[ Gravatar Icon ]

Jessi Hance#11

@Louis: apology accepted. I absolutely believe you had good intentions. However, I’d appreciate it so much if in future, you only answer questions I actually ask. If you have criticism or qualifications of the article, great, but they should be addressed to the author, or everyone in general, not me! Thanks Louis, I do wish you the best.

[ Gravatar Icon ]

Jonathan Ellse#12

Thanks for this. It has knocked about 10% of most of my PNGs.

[ Gravatar Icon ]

hK#13

Irfanview has the RIOT plugin, which can reduce jpg, png and gif. But it doesn’t just optimize blindly, but gives a side-by-side comparison view. It has worked well for my uses.. :)

[ Gravatar Icon ]

Louis#14

@hK: that plugin sounds awesome. Do you know of any mac equivalent?

[ Gravatar Icon ]

Monkey#15

WOW Definitely a great article. While I’ve yet to test it, I’m excited about it!

All I use are PNG’s, and any sort of optimization, let-alone lossless?! optimization, is crazy!

Thanks, as always!

-Monkey

[ Gravatar Icon ]

Jeff Starr#16

@Patternhead: Good point — I should have mentioned that I do that step as well: all of my PNG images are “Saved for Web” in Photoshop. Even without that step, however, I think that OptiPNG and Smush.it would collectively remove any of the extraneous information not otherwise eliminated via Photoshop.

@Louis: As always, thanks for sharing your expertise. I will be checking out Ping very soon.

@Jessi Hance: Glad to hear you appreciate the article. Likewise, I am grateful for you taking the time to share your thoughts and feedback.

@Austin Dworaczyk Wiltshire: Thanks for the tip! I had not heard of PNGOUT but will be trying it soon. I also use Irfanview so that’s a total bonus. :)

@Jonathan Ellse: Awesome! That’s great to hear :)

@hK: Another new plugin to experiment with! It’s like Christmas all over again. Thanks for the tip on RIOT — looking forward to trying it out.

@Monkey: My pleasure — thank you for the great feedback! :)

[ Gravatar Icon ]

Permana Jayanta#17

Same with patternhead, I just save for web in PNG format. This is great information for me. I’m going to try it to optimize PNG image with transparency

[ Gravatar Icon ]

Derek Tonn#18

Good work, Jeff! I blogged about your article tonight (http://graphicsoptimization.com/blog/?p=693), and would highly recommend giving PNGSlim a try: http://people.bath.ac.uk/ea2aced/tech/png/pngslim.zip A free tool that has literally changed the way I optimize .png files forever! A bit slow related to processing large images, but incredibly easy to use…and you’ll be hard-pressed to achieve better resulting file size reductions using any other tool. Hope that helps! - Derek

[ Gravatar Icon ]

Jacob Rask#19

Nice article! OptiPNG was much more effective than both smush.it and PNGcrush for me, btw. As much as 50% size decrease with -o7 on some files. Running both PNGcrush and OptiPNG on the same file simply gave the same result as only running OptiPNG. Didn’t try smushing them afterwards though, since smush.it’s uploader didn’t work for me.

[ Gravatar Icon ]

Nihar#20

Great, i will use these tools to optimize the images that i am using for my blog.

Thanks for sharing this..

[ Gravatar Icon ]

Jeff Starr#21

@Derek Tonn: Thank you kindly for the information, Derek. I am all over PNGSlim and will be experimenting with it during my next design project (currently in progress). If it works as good as demonstrated in your post, then I will certainly be integrating it into my image-optimization routine. Many thanks! :)

@Jacob Rask: Yes, I find the same thing — OptiPNG seems to always outperform the others (although I am now anxious to try PNGSlim on Derek’s recommendation). Even with the great optimization from OptiPNG, however, running my files through Smush.it usually bangs out an additional few bytes. Any ideas why the uploader may not be working for you?

@Nihar: My pleasure — thanks for the feedback! :)

[ Gravatar Icon ]

Jeff Starr#23

@Taimar: Normally I delete one-word comments or comments that provide only a link, but since that URL seems absolutely relevant and possibly may be a great PNG optimization app, I will let it slide. Although, next time you should take the time to type a few words about the link to let readers know why you are leaving it or what you think about it. In any case, thanks.

[ Gravatar Icon ]

Taimar#24

OK, sorry about that. I’m adding this info now:

PngOptimizer is in my opinion the best PNG optimizing tool for Windows out there. It’s easy (has GUI, isn’t command line), fast and efficient. And it’s free. :)

Version 1.8 works also with 64bit Vista.

[ Gravatar Icon ]

Louis#25

@Taimar: mac users need love too! :(

[ Gravatar Icon ]

Louis#27

@Taimar: well, thank you very much! You sir are quite a gentleman. I didn’t know about these apps, and God, they look awesome!

[ Gravatar Icon ]

Phil Nelson#28

Thanks for the PNGPress shout-out, Taimar!

[ Gravatar Icon ]

Taimar#29

You’re Welcome :)

[ Gravatar Icon ]

Narayan @ contenta converter#30

Great post. Thanks for the information and link to optiPNG.

[ Gravatar Icon ]

Vladimir#31

In Linux:

find -type f -name "*.png" -exec optipng -o9 '{}' \;
find -type f -name "*.gif" -exec gifsicle -O2 -b '{}' \;

:-)

[ Gravatar Icon ]

Conrad Chu#32

I’ve been working on a service similar to smush.it called punypng.

It’s free and just another contribution towards making the web more puny.
http://www.gracepointafterfive.com/punypng

[ Gravatar Icon ]

Nicholas Storman#33

Just curious which settings do you use in save for web in Photoshop?

[ Gravatar Icon ]

Jeff Starr#34

Hi Nicholas, it really all depends on the purpose of the image. For JPEG files, I like to find the right balance between smaller file size and quality, which generally happens for me in the 66% - 88% range. For PNG files, I use 8-bit for GIF-like images and 32-bit when alpha transparency is required. GIF files are usually set with 128 - 256 color pallets, unless the image is suitable for fewer colors. Other settings vary, depending on the project, etc.

[ Gravatar Icon ]

Sunny Senevirathne#35

I am trying to find a technique for optimize character searching mechanism for Unicode characters..If any of you know any method to efficiently search Unicode characters please let me know. Thanks!

[ Gravatar Icon ]

Dan Craggs#36

The ‘-o 7’ parameter isn’t the most intensive for optipng. If you want to try all possibilities you need this:

optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 filename.png

[ Gravatar Icon ]

Shane#37

For the more lazy among us, I just use ImageOptim for the Mac.

http://imageoptim.pornel.net/

Works great at compressing PNGs and JPGs.

[ Gravatar Icon ]

Vincent RABAH#38

93K vincent-round-full.png the original (a picture of me)

pngquant 256 vincent-round-full.png :
33K vincent-round-full-quant-256Colors.png

pngquant 128 vincent-round-full.png :
26K vincent-round-full-quant-128Colors.png

The result is quite impressive :)

[ Gravatar Icon ]

Stephen Bell#39

If you really want smaller PNGs, make this your first step:

1. Posterize in Photoshop (Image > Adjust > Posterize). Start at worst quality, then bump it up until it looks acceptable.

This will make things a lot smaller, then you can continue through your PNG optimizers of choice.

More complicated tips in the same vein here:
http://www.smashingmagazine.com/2009/07/15/clever-png-optimization-techniques/

I would also put in a plug for PunyPNG because of this:
http://www.gracepointafterfive.com/punypng-now-supports-dirty-transparency

[ Gravatar Icon ]

Jeff Starr#40

@Dan Craggs: That looks like some powerful stuff. Do you have a favorite reference that covers more of that same level of technique? Much of what I managed to find was mostly just the basics.

@Shane: I consider myself lazy, so thanks for the tip.

@Vincent RABAH: “Most impressive.” pngquant is incredible.

@Stephen Bell: Sweet tip. Why didn’t I think of posterizing first. It makes so much sense. What is generally a range that is useful when trading between quality and file size? Less than 256? 128? (completely guessing here)

[ Gravatar Icon ]

Dan Craggs#41

Jeff: Just had a browse through optipng’s documentation one day, and that detail was there along with a notice saying, essentially, ‘you’re probably not gonna want to do this in most cases…’

On most images, pngout tends to struggle to improve on the exhaustive optipng search. Messing around with its block sizes tends to work on occasion though.

[ Gravatar Icon ]

Stephen Bell#42

@Jeff Starr: I recently did a website with a LOT of transparent PNGs (admittedly, this made for a fairly heavy site):

http://www.okcadclub.com/addy2010

I’m sure it would be different if you’re doing photos, but on textured, cartoony characters like these, my range on Posterize was between 17 and 25, with almost no discernible difference from the originals. I don’t think the “Levels” on the Posterize dialog corresponds to the number of colors shown (setting it at 2 gives me 6 or 7 distinct colors).

[ Gravatar Icon ]

Sean T Allen#43

We run all our pngs through pngcrush with the following options and it results in images that smush it can’t compress any further:

pngcrush -q -rem alla -brute -reduce ORIGFILE CRUSHED FILE

For gif and jpegs, you can also use…

gifsicle and jpegtran

this simple ruby script will do all 3 for you if handed a directory:

#!/usr/bin/ruby

require 'find'

Find.find( ARGV[0] ) do | file |
     if file.match( '\.gif$' )
          command = sprintf( 'gifsicle --batch -O2 %s', file )
          puts command
          system( command )
     end
     if file.match( '\.jpe?g$' )
          command = sprintf( 'jpegtran -copy none -optimize -outfile %s %s', file, file )
          puts command
          system( command )
     end
     if file.match( '\.png$' )
          new_file = "#{file}-crushed"
          command = sprintf( 'pngcrush -q -rem alla -brute -reduce %s %s', file, new_file )
          puts command
          system( command )
          if File.exists?( new_file )
               if File.size( new_file) < File.size( file )
                    command = "mv #{new_file} #{file}"
               else
                    command = "rm #{new_file}"
               end
               puts command
               system( command )
          end
     end
end

[ Gravatar Icon ]

Javier Mateos#44

Wow! This looks amazing, just tryed this out and saved around 19% using PNG Crush, thanks for this nice post! Just Stumbled it! :)

[ Gravatar Icon ]

Cricket La Chica#45

Hi, thanks for this post. Very useful stuff! Although I do have a question: how do you use OptiPNG on a Mac?

[ Gravatar Icon ]

Jeff Starr#46

@Stephen Bell: Thanks. That’s good to know and a great site design btw. Loaded very quickly. I think it will be interesting to experiment with posterization for photos next time I’m in Photoshop. Could be a great optimization tool to have available.

@Sean T Allen: That’s a little over my head, but thanks for sharing for others to benefit from. Looks like some powerful stuff there.

@Javier Mateos: Thanks for the stumble :)

@Cricket La Chica: Not sure, I have only used it with PC, but I did see some Mac stuff on the OptiPNG home page.

[ Gravatar Icon ]

Shane#47

Great tips here, i’ve just got my hands on RIOT, and what a dream.
My sites full of jpegs, so it’s perfect.
Reduces files sizes from 14kb to 2kb without too much loss of image quality. Acceptable for “adverts” and smaller images.
My dream come true,
thanks

Trackbacks / Pingbacks
  1. Pages tagged 'minute'
  2. Daily Links | AndySowards.com :: Professional Web Design, Development, Programming, Hacks, Downloads, Math and being a Web 2.0 Hipster?
  3. Graphics Optimization Blog » Blog Archive » Review of the 5-Minute PNG Image Optimization blog posting by Jeff Starr
  4. magnus.de
  5. OptiPNG 0.6.2.1 x64 — nuke it dot org
  6. Optimizing PNG images: PNGGauntlet | Blog - PSD to HTML - CSS WITH COLOUR (Frontend Development)
  7. 10 Ways to Instantly Speed Up Your Website | DevMoose
  8. Guida per ottimizzare un immagine PNG in 5 minuti
  9. 5-Minute PNG Image Optimization • Perishable Press « Netcrema – creme de la social news via digg + delicious + stumpleupon + reddit
Share your thoughts..

Read Comment Policy

Comment Rules: No spam. No profanity. Use your real name. You may use simple HTML tags for style. Wrap all code in <code> tags. Learn more.



Attention: Do NOT follow this link!