6 ms·
Pngquant – Lossy PNG compressor
- pstadler 13y agoAvailable in Homebrew: brew install pngquant
- adamjernst 13y agopngquant is great. I make an iPhone app that displays transit maps. Transit maps are ideal candidates for quantization (limited color range, large blocks of color that are perfect for RLE) and I saved a lot of file size by quantizing the map tiles. Thanks pngquant!
- SquareWheel 13y agoSounds like vector images could be used effectively there.
- rockdoe 13y agoThe algorithms link is broken.
- Gigablah 13y agoThis is how I use pngquant in my thumbnailing workflow: https://gist.github.com/gigablah/3110899 https://gist.github.com/gigablah/3110899 At 100x100 pixels, I find that this produces small (~8kb) PNG thumbnails which are still sharp with no noticeable color loss. (Disclaimer: I'm a beginner at nodejs)
- ericthegoodking 13y agoI like this small program , great for compressing png files. Congrats dev.
- chipaca 13y agoHow is this different from `pngnq` (that's been around for ages)?
- saurik 13y agoIf you use Google to ask this question the first hit is actually the pngnq website, which explicitly states that pngnq is a modification of pngquant, and supposedly an improvement. http://pngnq.sourceforge.net http://pngnq.sourceforge.net > Pngnq is an adaptation by Stuart Coyle of Greg Roelf's pnqquant using Anthony Dekker's neuquant algorithm. > Why another quantizer? > Pngnq exists because I needed a lot (several thousand) of png images in RGBA format to be quantized. After some searching, the only tool I could find that worked for RGBA was pngquant. I tried pngquant but found that the median cut algorithm that it uses, with or without dithering, gave inferior looking results to the neuquant algorithm. You can see the difference demonstrated on the neuquant page.
- leephillips 13y agoI compared them recently for a project where I needed to make some PNGs smaller, and settled on pngng, which, in my informal testing, seemed to produce better results.
- pornel 13y agoMake sure you haven't tested the 13-years-old pngquant 1.0 that is shipped with Debian stable and some other distros. pngquant2 should clearly beat pngnq.
- leephillips 13y agoI tested v. 1.0-4.1 that comes with Ubuntu 12.04.1 (I think). Am I missing out?
- pornel 13y agoYes. 1.0 was written in the MS-DOS era, truncates quality to 15-bits, has buggy alpha and uses basic Median Cut algorithm from early 80s. 2.0 is by now a totally different program, with expanded and improved algorithms (with bits of machine learning) and uses 128 bits per pixel precision (SIMD+multicore optimized).
- alexdowad 13y agoWOW!!! I just applied this to the (big) PNG sprite files used in a project I am working on now, and the gains in file size were amazing! And with hardly any difference in quality! Who ever said that reading Hacker News was a productivity drain?
- nitrogen 13y agoSome alternatives while you're thinking about the subject: png-nq, pngcrush, optipng. I'm sure there are others. If I want an image small, I try all of them and pick the best.
- pbhjpbhj 13y agoI don't know png-nq¹ but in their default use pngcrush and optipng aren't [direct] alternatives to pngquant. Optipng and pngcrush do lossless recompression and the program in the OP AFAICT does lossy compression to create an image encoded in to PNG without an intermediate representation. As I understand it pngcrush will reduce the bit-size or apply a new palette if that will reduce the file-size without loss of pixel data. Optipng can optionally add lossy compression too. ¹ - https://github.com/stuart/pngnq https://github.com/stuart/pngnq looks like it was inspired by pngquant, from that page: >Pngnq exists because I needed a lot of png images in RGBA format to be quantized. After some searching, the only tool I could find that worked was pngquant. I tried pngquant but found that the median cut algorithm that it uses, with or without dithering, gave inferior looking results to the neuquant algorithm. You can see the difference demonstrated on the neuquant web page: http://members.ozemail.com.au/~dekker/NEUQUANT.HTML http://members.ozemail.com.au/~dekker/NEUQUANT.HTML . //
- riffraff 13y agoin my experiments pngnq worked better than pngquant but pngquant2 works better than pngnq.
- xlevus 13y agoSome examples would be nice.
- codelike 13y agoThis page has some comparison examples: http://bugfixer.endel.me/2012/09/23/comparison-between-png-quantizers/ http://bugfixer.endel.me/2012/09/23/comparison-between-png-q...
- pornel 13y agohttp://pngquant.org/vsphotoshop.html http://pngquant.org/vsphotoshop.html You can try yourself at http://tinypng.org http://tinypng.org
- leeoniya 13y agoshameless self-promotion: demo: http://o-0.me/RgbQuant/ http://o-0.me/RgbQuant/ repo: https://github.com/leeoniya/RgbQuant.js https://github.com/leeoniya/RgbQuant.js * doesnt support alpha channel or dithering (yet)
- Gravityloss 13y agoVery good, but looking at the examples, the smooth gradients look awful. They would benefit from some noise to hide the transitions, but then the compression would suffer. Maybe some more palette entries for large smooth areas.
- leeoniya 13y agoif you jack the minHueCols param up to 4096 or 8192, it does much better in many cases of gradients but also much slower. it's certainly not a complete hands-off quantizer. the best results i've found for 0-config quantizarion is Wu's Color Quantizer v2 [1] implementation [2] [1] http://www.ece.mcmaster.ca/~xwu/cq.c http://www.ece.mcmaster.ca/~xwu/cq.c [2] http://nquant.codeplex.com/ http://nquant.codeplex.com/
- pornel 13y agoThere is a version of pngquant that uses Wu's algorithm: https://github.com/pornel/pngquant/tree/wucut https://github.com/pornel/pngquant/tree/wucut However, Wu's algorithm requires preprocessing R * G * B * A * int array, which is 16GB of RAM if done at full RGBA quality, so in practice all implementations have to drop alpha and/or heavily posterize colors. pngquant the same goal — subdivides RGBA (hyper)cube to minimize variance in each section — but does it with much less memory and can do it at full quality. Posterization of input is my pet peeve, as it gives images slightly banded and grainy look that we associate with "256-color" images (since VGA only ever supported 6-bit per gun), and presume 256 colors are never enough for photorealistic look — but it often is, and people who use e.g. TinyPNG service think it's magic.
- leeoniya 13y ago
- kraken-io 13y agoAs kraken.io, we can safely say that this is indeed an excellent program, and it makes up part of our lossy PNG optimization stack.
- noiv 13y agoAny link to the 2.0 32bit deb?
- webjunkie 13y agoUse ImageAlpha as a GUI for OSX. Very nice results! http://pngmini.com/ http://pngmini.com/
- seanalltogether 13y agoI've never quite understood how its possible to create better encoders without needing a new decoder on the other end. Can anyone explain how this works? When you're writing a png decoder, why wouldn't there just be one optimal png encoder to go along with it?
- pornel 13y agoIn lossy encoding you throw away data to get smaller file, and the art is in deciding which data you throw away. In this case you need to do vector quantization — choose 256 colors (decoder's hard limit) that best represent thousands of different colors in the source image, e.g. you have to decide whether to use a palette entry for just a single red pixel, or maybe sacrifice that pixel and use the palette entry to improve smoothness of a more visible blue gradient.
- simonw 13y agoThis is a lossy encoder, which means that the image that comes out the other end doesn't contain exactly the same information as the image that goes in. You can use all kinds of cleverness that is mostly unrelated to the actual image format itself to shrink the size of an image. Here's one example: if an image uses millions of colours, you could drop it down to just using a few hundred colours (picking the nearest colour from your pallette to each of the pixels) and hence shrink the filesize a whole bunch. There are lots of different approaches to picking that initial pallette though - you might do it based on averaging out the pixel colours, or maybe you know something about human visual colour perception and can hence behave differently for colours that you don't think people will notice as easily.
- radarsat1 13y agoGlobally, because encoding and decoding are not the same thing. Encoding requires making choices about what to throw away, but decoding is just putting them back together. Mathematically you can think about encoding as converting to some matrix representation that has a lot of zeros -- the process to take that matrix and reconstruct the image doesn't depend on how many zeros there are, but the efficiency of the encoder does. Perhaps an easier way to think about it from a programmer perspective.. a decoder is a programming language interpreter that takes a program and generates the data. The encoder is something that generates a program in that language. So you can see that the decoder is quite straight-forward, while the encoder has a lot of choices to make about how best to represent the data as a program in the decoder's language.
- kristofferR 13y agoThe ImageOptim/ImageAlpha OS X apps are fantastic for compressing all kinds of images for the web. http://imageoptim.com/ http://imageoptim.com/ http://pngmini.com/ http://pngmini.com/
- amadeus 13y agoIt should be noted that ImageAlpha, the app under the pgnmini.com url, provides a GUI to to PNGQuant and PNGNQ. While a command line tool is useful by itself, using lossy compression is best done in a GUI to determine how much compression draws the right balance between file size and its loss in quality. ImageAlpha is amazing for this.
- j_s 13y agoRead more about the details of implementing something like this in C#: http://www.mattwrock.com/post/2011/09/05/Convert-32-bit-PNGs-to-high-quality-8-bit-PNGs-with-C.aspx http://www.mattwrock.com/post/2011/09/05/Convert-32-bit-PNGs...
- frncscgmz 13y agoAnyone knows of a similar tool for jpeg images?
- blacksmith_tb 13y agoJpegs are already lossy, but if you want to increase the lossiness (and decrease filesize)via the commandline, you can do that with imagemagick or graphicsmagick with the -quality flag on a convert.
- SquareWheel 13y agoI use jpegtran for lossless. I've had good luck with http://jpeg-optimizer.com/ http://jpeg-optimizer.com/ for lossy.
- d0ugie 13y agoyeah, cwebp, works on jpeg effectively, gifs and pngs (pngs with a 30% lossless savings, much more if lossy), does some tricks pngs don't..
- btbuildem 13y agoYou should showcase at least a single sample of a compressed vs uncompressed image right there on the first page, before the Features section.
- faxenoff 13y agoHow about Color Quantizer? I use it for years. http://www.softpedia.com/get/Multimedia/Graphic/Graphic-Others/Color-quantizer.shtml http://www.softpedia.com/get/Multimedia/Graphic/Graphic-Othe... Offical site http://x128.ho.ua/color-quantizer.html http://x128.ho.ua/color-quantizer.html
- zw123456 13y agoVery timely, I was just working on a page that had to display complex graphs and the regular PNG's were huge. I set the quality to 50% and it reduced the size to about 30% of the original and it still looks good. Thank you!
- blueskin_ 13y agoLossy PNG compression is like trying to use a Ferrari to pull a 35 tonne trailer. PNG is for graphics; JPEG is for photos.