Size: 1123
Comment: Add JPEG and PNG
|
Size: 2985
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 19: | Line 19: |
Other useful stuff: {{{#!highlight sh numbers=off parallel -u 'echo {}; cjpeg -outfile {}.mozjpeg -optimise -progressive -quality 90 {} && mv {}.mozjpeg {}' ::: *.jpg parallel -u 'echo {}; convert {} -sampling-factor "2x2,1x1,1x1" {}.422 && mv {}.422 {}' ::: *.jpg }}} |
|
Line 20: | Line 27: |
=== 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: {{{#!highlight sh numbers=off 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: {{{#!highlight sh #!/bin/sh for i in "$@"; do pngnq -e .png.8 -n 256 $i mv $i.8 $i done optipng -quiet -o3 $@ advpng -z -4 $@ advdef -z -4 $@ }}} which you can run in parallel with: {{{#!highlight sh numbers=off find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) optimize-png-8bit }}} === Full color === |
|
Line 26: | Line 64: |
# Or (untested) parallel -u'optipng -o3 {}; advpng -z -4 {}; advdev -z 4 {}' -n 64' ::: *png |
# Or parallel -n 64 -u 'optipng -o3 {}; advpng -z -4 {}; advdef -z -4 {}' ::: *png |
Line 29: | Line 67: |
To take advantage of OS file caching, PNG optimization can be wrapped into a script, optimize-png: {{{#!highlight sh #!/bin/sh optipng -quiet -o3 $@ advpng -z -4 $@ advdef -z -4 $@ }}} which you can run in parallel with: {{{#!highlight sh numbers=off find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) optimize-png }}} pngcrush is another tool that unfortunately does not work as well as the above, but can be run in parallel with: {{{#!highlight sh numbers=off parallel -u 'echo {}; pngcrush -reduce -brute {} {}.pngcrush && mv {}.pngcrush {}' ::: *.png # Remove color space information parallel -u 'echo {}; pngcrush -reduce -brute -rem gAMA -rem cHRM -rem iCCP -rem sRGB {} {}.pngcrush && mv {}.pngcrush {}' ::: *.png }}} |
|
Line 30: | Line 92: |
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.
Other useful stuff:
parallel -u 'echo {}; cjpeg -outfile {}.mozjpeg -optimise -progressive -quality 90 {} && mv {}.mozjpeg {}' ::: *.jpg
parallel -u 'echo {}; convert {} -sampling-factor "2x2,1x1,1x1" {}.422 && mv {}.422 {}' ::: *.jpg
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:
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 -n 64 -u 'optipng -o3 {}; advpng -z -4 {}; advdef -z -4 {}' ::: *png
To take advantage of OS file caching, PNG optimization can be wrapped into a script, optimize-png:
which you can run in parallel with:
find . -name '*png' -print0 | xargs -0 -n64 -P$(nproc) optimize-png
pngcrush is another tool that unfortunately does not work as well as the above, but can be run in parallel with:
parallel -u 'echo {}; pngcrush -reduce -brute {} {}.pngcrush && mv {}.pngcrush {}' ::: *.png
# Remove color space information
parallel -u 'echo {}; pngcrush -reduce -brute -rem gAMA -rem cHRM -rem iCCP -rem sRGB {} {}.pngcrush && mv {}.pngcrush {}' ::: *.png