home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pnm / pnmmargin < prev    next >
Text File  |  1993-10-04  |  2KB  |  87 lines

  1. #!/bin/sh
  2. #
  3. # ppmmargin - add a margin to a portable anymap
  4. #
  5. # Copyright (C) 1991 by Jef Poskanzer.
  6. #
  7. # Permission to use, copy, modify, and distribute this software and its
  8. # documentation for any purpose and without fee is hereby granted, provided
  9. # that the above copyright notice appear in all copies and that both that
  10. # copyright notice and this permission notice appear in supporting
  11. # documentation.  This software is provided "as is" without express or
  12. # implied warranty.
  13.  
  14. tmp1=/tmp/pnmm1$$
  15. tmp2=/tmp/pnmm2$$
  16. tmp3=/tmp/pnmm3$$
  17. tmp4=/tmp/pnmm4$$
  18. rm -f $tmp1 $tmp2 $tmp3 $tmp4
  19.  
  20. color="-gofigure"
  21.  
  22. # Parse args.
  23. while true ; do
  24.     case "$1" in
  25.     -w* )
  26.     color="-white"
  27.     shift
  28.     ;;
  29.     -b* )
  30.     color="-black"
  31.     shift
  32.     ;;
  33.     -c* )
  34.     shift
  35.     if [ ! ${1-""} ] ; then
  36.         echo "usage: $0 [-white|-black|-color <colorspec>] <size> [pnmfile]" 1>&2
  37.         exit 1
  38.     fi
  39.     color="$1"
  40.     shift
  41.     ;;
  42.     -* )
  43.     echo "usage: $0 [-white|-black|-color <colorspec>] <size> [pnmfile]" 1>&2
  44.     exit 1
  45.     ;;
  46.     * )
  47.     break
  48.     ;;
  49.     esac
  50. done
  51.  
  52. if [ ! ${1-""} ] ; then
  53.     echo "usage: $0 [-white|-black|-color <colorspec>] <size> [pnmfile]" 1>&2
  54.     exit 1
  55. fi
  56. size="$1"
  57. shift
  58.  
  59. if [ ${2-""} ] ; then
  60.     echo "usage: $0 [-white|-black|-color <colorspec>] <size> [pnmfile]" 1>&2
  61.     exit 1
  62. fi
  63.  
  64. # Capture input file in a tmp file, in case it's a pipe.
  65. cat $@ > $tmp1
  66.  
  67. # Construct spacer files.
  68. case "$color" in
  69.     -gofigure )
  70.     pnmcut 0 0 1 1 $tmp1 | pnmtile $size 1 > $tmp2
  71.     ;;
  72.     -white | -black )
  73.     pbmmake $color $size 1 > $tmp2
  74.     ;;
  75.     * )
  76.     ppmmake $color $size 1 > $tmp2
  77.     ;;
  78. esac
  79. pnmflip -rotate90 $tmp2 > $tmp3
  80.  
  81. # Cat things together.
  82. pnmcat -lr $tmp2 $tmp1 $tmp2 > $tmp4
  83. pnmcat -tb $tmp3 $tmp4 $tmp3
  84.  
  85. # All done.
  86. rm -f $tmp1 $tmp2 $tmp3 $tmp4
  87.