summaryrefslogtreecommitdiff
path: root/localsvg2ico
blob: bf7b441ce43b25dd1e768581669ed5552654b9fe (plain)
  1. #!/bin/sh
  2. # Copyright © 2011 Jonas Smedegaard <dr@jones.dk>
  3. # Description: Create favicon from SVG file
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Depends: inkscape, netpbm
  19. #
  20. # TODO: Use tempdir
  21. # TODO: Check and ask if outfile already exist
  22. # TODO: Add --force option to skip asking for overwriting
  23. set -e
  24. infile="$1"
  25. id="$2"
  26. if ! [ -s "$infile" ]; then
  27. echo "Error: wrong inputfile \"$infile\" provided!"
  28. echo
  29. echo "Usage: $0 SVGFILE [OBJECT-ID]"
  30. exit 1
  31. fi
  32. dir=$(dirname "$infile")
  33. stem=$(basename "$infile" | sed 's/\..*//')
  34. mkpgmpluspgm() {
  35. set -e
  36. size="$1"
  37. depth="$2"
  38. inkscape -w $size ${id:+-i "$id"} -e "$dir/${stem}-$size.png" "$infile" >/dev/null
  39. # fIXME: reduce colors, but only when needed (else pnmquant fails)
  40. # pngtopnm "$dir/${stem}-$size.png" | pnmquant $depth > "$dir/${stem}-$size.ppm"
  41. pngtopnm "$dir/${stem}-$size.png" > "$dir/${stem}-$size.ppm"
  42. pngtopnm -alpha "$dir/${stem}-$size.png" > "$dir/${stem}-$size.pgm"
  43. echo "$dir/${stem}-$size.ppm" "$dir/${stem}-$size.pgm"
  44. }
  45. pnmfiles="$pnmfiles $(mkpgmpluspgm 16 16)"
  46. pnmfiles="$pnmfiles $(mkpgmpluspgm 32 16)"
  47. pnmfiles="$pnmfiles $(mkpgmpluspgm 48 256)"
  48. ppmtowinicon -output "$dir/${stem}.ico" -andpgms $pnmfiles
  49. rm $dir/${stem}-??.png $pnmfiles