Ubuntu – How to get maximal compressed screenshots

compressionemailscreenshot

I'd like to compress my screenshots as much as possible before I send them via email. The best compression ratio I only got with some work on each screenshot:

  • first I took the screenshot with shutter: 1920x1080px, PNG compression 9 -> around 450Kb
  • then I uploaded it to http://tinypng.org/ -> got the same picture with quantisation but only around 150Kb left

how could I achieve such a good compression within a screenshot tool like shutter?

The technique of http://tinypng.org seems fabulous:

similar colours in your image are combined. This technique is called “quantisation”. Because the number of colours is reduced, 24-bit PNG files can be converted to much smaller 8-bit indexed colour images. All unnecessary metadata is stripped too. The result: tiny 8-bit PNG files

But shutter has no "quantisation" option.

The Quality is not that important, I wouldn't mind to have it more lossy. Maybe with GIF it would be possible to compress smaller? Or with less colors?

Best Answer

optipng is certainly worth a look at . It's command-line but you could write a .desktop handler for it. It's fairly simple to use for batching:

optipng -o7 *.png

But note it's destructive. It will overwrite your files. This is usually fine but if you're using a fat format (Adobe Fireworks PNG for example), you might lose useful. Here is the full list of options:

$ optipng -h
OptiPNG 0.6.4: Advanced PNG optimizer.
Copyright (C) 2001-2010 Cosmin Truta.

Synopsis:
    optipng [options] files ...
Files:
    Image files of type: PNG, BMP, GIF, PNM or TIFF
Basic options:
    -?, -h, -help   show this help
    -o <level>      optimization level (0-7)        default 2
    -v          verbose mode / show copyright and version info
General options:
    -fix        enable error recovery
    -force      enforce writing of a new output file
    -keep       keep a backup of the modified files
    -preserve       preserve file attributes if possible
    -quiet      quiet mode
    -simulate       simulation mode
    -snip       cut one image out of multi-image or animation files
    -out <file>     write output file to <file>
    -dir <directory>    write output file(s) to <directory>
    -log <file>     log messages to <file>
    --          stop option switch parsing
Optimization options:
    -f  <filters>   PNG delta filters (0-5)         default 0,5
    -i  <type>      PNG interlace type (0-1)        default <input>
    -zc <levels>    zlib compression levels (1-9)       default 9
    -zm <levels>    zlib memory levels (1-9)        default 8
    -zs <strategies>    zlib compression strategies (0-3)   default 0-3
    -zw <window size>   zlib window size (32k,16k,8k,4k,2k,1k,512,256)
    -full       produce a full report on IDAT (might reduce speed)
    -nb         no bit depth reduction
    -nc         no color type reduction
    -np         no palette reduction
    -nx         no reductions
    -nz         no IDAT recoding
Optimization details:
    The optimization level presets
        -o0  <=>  -o1 -nx -nz
        -o1  <=>  [use the libpng heuristics]   (1 trial)
        -o2  <=>  -zc9 -zm8 -zs0-3 -f0,5    (8 trials)
        -o3  <=>  -zc9 -zm8-9 -zs0-3 -f0,5  (16 trials)
        -o4  <=>  -zc9 -zm8 -zs0-3 -f0-5    (24 trials)
        -o5  <=>  -zc9 -zm8-9 -zs0-3 -f0-5  (48 trials)
        -o6  <=>  -zc1-9 -zm8 -zs0-3 -f0-5  (120 trials)
        -o7  <=>  -zc1-9 -zm8-9 -zs0-3 -f0-5    (240 trials)
    The libpng heuristics
        -o1  <=>  -zc9 -zm8 -zs0 -f0        (if PLTE is present)
        -o1  <=>  -zc9 -zm8 -zs1 -f5        (if PLTE is not present)
    The most exhaustive search (not generally recommended)
      [no preset] -zc1-9 -zm1-9 -zs0-3 -f0-5    (1080 trials)
Examples:
    optipng file.png                (default speed)
    optipng -o5 file.png            (moderately slow)
    optipng -o7 file.png            (very slow)
    optipng -i1 -o7 -v -full -sim experiment.png

There are other tools (pngcrush for example) and you might find they're more useful but I've never strayed from optipng, just for its no-nonsense simlpicity.

There's a fairly comprehensive PNG compression shoot-out here that's quite fun: