#!/bin/bash ## mkfavicon -- convert any image into the FAVICON-format -- by Eugene Reimer, 2007-Apr; ## using ppmtowinicon, which was included with Fedora-linux (is part of netpbm package); ## png2ico is a very similar utility in a separate package (have it also) -- will use it when wanting transparency (see mkfavicon-transparent). ## ## the ppmtowinicon documentation says Microsoft recommends including 16x16 (16-color), 32x32 (16-color), and 48x48 (256-color) images; ## but that seems a waste of bandwidth, as it makes a big file, and most browsers never use anything other than 16x16; ## I made nativeorchid's favicon.ico that way (except for max 64-colors?), for a filesize of 3638 bytes; ## making it with only the first two image-sizes, yields a filesize of 1078 bytes; ## using only a 16x16 image, yields a filesize of 318 bytes; (these filesizes are independent of image complexity) ## ## if input image is smaller than 32x32, then makes only the 16x16 size; otherwise makes both 16x16 and 32x32 sizes, each in 16-colours. OF=favicon.ico; [ $# -ge 2 ] && OF=$2; ##optional 2nd param is the result-name (default: favicon.ico) convert $1 tmp$$.ppm ##convert input to PPM w=$(pnmfile tmp$$.ppm |gawk '{ print $4 }') ##get w=width of image h=$(pnmfile tmp$$.ppm |gawk '{ print $6 }') ##get h=height of image pnmscale -xysize 16 16 tmp$$.ppm 2>/dev/null >tmp$$16r.ppm; pnmquant 16 tmp$$16r.ppm >tmp$$16.ppm ##convert to 16x16 pixels in 16-colours if ((w*h >= 32*32)); then pnmscale -xysize 32 32 tmp$$.ppm 2>/dev/null >tmp$$32r.ppm; pnmquant 16 tmp$$32r.ppm >tmp$$32.ppm ##convert to 32x32 pixels in 16-colours ppmtowinicon tmp$$16.ppm tmp$$32.ppm >$OF ##produce favicon output file containing both 16x16 and 32x32 images echo "wrote $OF with 16x16 and 32x32 images" else ppmtowinicon tmp$$16.ppm >$OF ##produce favicon output file containing only 16x16 image echo "wrote $OF with 16x16 image only" fi rm tmp$$*.ppm ##yank this to debug using tmp files