Differences between revisions 2 and 3
Revision 2 as of 2011-09-10 07:20:38
Size: 2287
Editor: SamatJain
Comment: More detail about PNG optimization
Revision 3 as of 2011-09-29 22:30:14
Size: 2289
Editor: SamatJain
Comment:
Deletions are marked like this. Additions are marked like this.
Line 77: Line 77:
CategoryCategory CategoryCheatSheet

JPEG

jpegtran (part of libjpeg-progs in Debian) can losslessly optimize JPEG files:

parallel -u 'echo {}; jpegtran -optimize -progressive -perfect -copy all -outfile {}.tran {} && mv {}.tran {}' ::: *.jpg

Source: /dev/schnouki - Optimizing JPEG pictures

Another interesting tool is jpegoptim (jpegoptim on freshmeat):

parallel jpegoptim ::: *.jpg

though the compression does not appear to be as good, and it's known to wipe JPEG metadata even when told not to.

PNG

256 color (8-bit)

Converting to 8-bit PNG (maximum of 256 colors) saves a significant amount of space, though this should be done BEFORE other optimization:

find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) pngnq -e .8 -n 256
find . -name '*.8' -exec echo mv '{}' '{}'.png \; | sed 's/\.8\./\./'

To take advantage of OS file caching, 8-bit conversion and PNG optimization can be wrapped into a script, optimize-png-8bit:

   1 #!/bin/sh
   2 for i in "$@"; do
   3         pngnq -e .png.8 -n 256 $i
   4         mv $i.8 $i
   5 done
   6 optipng -quiet -o3 $@
   7 advpng -z -4 $@
   8 advdef -z -4 $@

which you can run in parallel with:

find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) optimize-png-8bit

Full color

find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) optipng -o3
find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) advpng -z -4
find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) advdef -z -4

# Or
parallel -u'optipng -o3 {}; advpng -z -4 {}; advdev -z 4 {}' -n 64 ::: *png

To take advantage of OS file caching, PNG optimization can be wrapped into a script, optimize-png:

   1 #!/bin/sh
   2 optipng -quiet -o3 $@
   3 advpng -z -4 $@
   4 advdef -z -4 $@

which you can run in parallel with:

find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) optimize-png


CategoryCheatSheet

SamatsWiki: CheatSheet/ImageOptimization (last edited 2020-04-06 10:04:17 by SamatJain)