#!/bin/sh # Copyright © 2011 Jonas Smedegaard # Description: Create favicon from SVG file # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Depends: inkscape, netpbm # # TODO: Use tempdir # TODO: Check and ask if outfile already exist # TODO: Add --force option to skip asking for overwriting set -e infile="$1" id="$2" if ! [ -s "$infile" ]; then echo "Error: wrong inputfile \"$infile\" provided!" echo echo "Usage: $0 SVGFILE [OBJECT-ID]" exit 1 fi dir=$(dirname "$infile") stem=$(basename "$infile" | sed 's/\..*//') mkpgmpluspgm() { set -e size="$1" depth="$2" inkscape -w $size ${id:+-i "$id"} -e "$dir/${stem}-$size.png" "$infile" >/dev/null # fIXME: reduce colors, but only when needed (else pnmquant fails) # pngtopnm "$dir/${stem}-$size.png" | pnmquant $depth > "$dir/${stem}-$size.ppm" pngtopnm "$dir/${stem}-$size.png" > "$dir/${stem}-$size.ppm" pngtopnm -alpha "$dir/${stem}-$size.png" > "$dir/${stem}-$size.pgm" echo "$dir/${stem}-$size.ppm" "$dir/${stem}-$size.pgm" } pnmfiles="$pnmfiles $(mkpgmpluspgm 16 16)" pnmfiles="$pnmfiles $(mkpgmpluspgm 32 16)" pnmfiles="$pnmfiles $(mkpgmpluspgm 48 256)" ppmtowinicon -output "$dir/${stem}.ico" -andpgms $pnmfiles rm $dir/${stem}-??.png $pnmfiles