From 4783d9be7f82668910efadf5abdce35a64ae72c8 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 18 Apr 2011 22:52:15 +0200 Subject: Add new localsvg2ico to create favicon from SVG file. --- localsvg2ico | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 localsvg2ico (limited to 'localsvg2ico') 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 +# 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 -- cgit v1.2.3