diff options
author | root <root@dharma.jones.dk> | 2011-04-18 22:52:15 +0200 |
---|---|---|
committer | root <root@dharma.jones.dk> | 2011-04-18 22:52:15 +0200 |
commit | 4783d9be7f82668910efadf5abdce35a64ae72c8 (patch) | |
tree | 1397a54e5f63641bb6ea0c27010a9543ebfcfe7a | |
parent | 13741699796e4caa79ac2465c2f4a1ab8b243857 (diff) |
Add new localsvg2ico to create favicon from SVG file.
-rwxr-xr-x | localsvg2ico | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/localsvg2ico b/localsvg2ico new file mode 100755 index 0000000..bf7b441 --- /dev/null +++ b/localsvg2ico @@ -0,0 +1,58 @@ +#!/bin/sh + +# Copyright © 2011 Jonas Smedegaard <dr@jones.dk> +# 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 <http://www.gnu.org/licenses/>. +# +# 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 |