about summary refs log tree commit diff
path: root/editor/pnmmargin
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-12-29 18:30:30 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-12-29 18:30:30 +0000
commita8e8081ad45817e02b83745dc2225413a8703f81 (patch)
tree9b3645a2b14acd5a4d47562aaef4fdddfc4d6752 /editor/pnmmargin
parent8d912e64333ff5ac88ca261b4c33c3232b83a8a0 (diff)
downloadnetpbm-mirror-a8e8081ad45817e02b83745dc2225413a8703f81.tar.gz
netpbm-mirror-a8e8081ad45817e02b83745dc2225413a8703f81.tar.xz
netpbm-mirror-a8e8081ad45817e02b83745dc2225413a8703f81.zip
handle zero margin
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@504 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/pnmmargin')
-rwxr-xr-xeditor/pnmmargin51
1 files changed, 33 insertions, 18 deletions
diff --git a/editor/pnmmargin b/editor/pnmmargin
index f7c30b25..51ebebe5 100755
--- a/editor/pnmmargin
+++ b/editor/pnmmargin
@@ -13,7 +13,7 @@
 
 tempdir="${TMPDIR-/tmp}/pnmmargin.$$"
 mkdir -m 0700 $tempdir || \
-  { echo "Could not create temporary file. Exiting."; exit 1;}
+  { echo "Could not create temporary file. Exiting." 1>&2; exit 1;}
 trap 'rm -rf $tempdir' 0 1 3 15
 
 tmp1=$tempdir/pnmm1
@@ -42,7 +42,7 @@ while true ; do
 	-c|-co|-col|-colo|-color )
 	shift
 	if [ ! ${1-""} ] ; then
-	    echo "usage: $0 [-white|-black|-color <colorspec>] <size> [pnmfile]" 1>&2
+       	    echo "usage: $0 [-white|-black|-color <colorspec>] <size> [pnmfile]" 1>&2
 	    exit 1
 	fi
 	color="$1"
@@ -71,23 +71,38 @@ if [ ${2-""} ] ; then
 fi
 
 # Capture input file in a tmp file, in case it's a pipe.
+# TODO: This code does not consider the case when the input file is specified
+# and there is also input coming in from a pipe.
+
 cat $@ > $tmp1
 
-# Construct spacer files.
-case "$color" in
-    -gofigure )
-    pnmcut 0 0 1 1 $tmp1 | pnmtile $size 1 > $tmp2
-    ;;
-    -white | -black )
-    pbmmake $color $size 1 > $tmp2
-    ;;
-    * )
-    ppmmake $color $size 1 > $tmp2
-    ;;
-esac
-pamflip -rotate90 $tmp2 > $tmp3
+if [ $size == 0 ] ; then
+    # Zero margin; just copy input to output
+    pamtopnm $plainopt $tmp1;
+else
+    # If -white or -black, write output with pnmpad and exit.
+    # Otherwise construct spacer files.
+    
+    case "$color" in
+        -gofigure )
+        pnmcut 0 0 1 1 $tmp1 | pnmtile $size 1 > $tmp2
+        ;;
+        -white | -black )
+        pnmpad $plainopt $color \
+            -left=$size -right=$size -top=$size -bottom=$size $tmp1
+        exit
+        ;;
+        * )
+        ppmmake $color $size 1 > $tmp2
+        ;;
+    esac
+    pamflip -rotate90 $tmp2 > $tmp3
+    
+    # Cat things together.
+    pnmcat -lr $tmp2 $tmp1 $tmp2 > $tmp4
+    pnmcat -tb $plainopt $tmp3 $tmp4 $tmp3
+fi
+
+
 
-# Cat things together.
-pnmcat -lr $tmp2 $tmp1 $tmp2 > $tmp4
-pnmcat -tb $plainopt $tmp3 $tmp4 $tmp3