Index: trunk/pstamp/src/ppstampArguments.c
===================================================================
--- trunk/pstamp/src/ppstampArguments.c	(revision 32370)
+++ trunk/pstamp/src/ppstampArguments.c	(revision 33378)
@@ -21,9 +21,11 @@
     fprintf(stderr, "\n");
     fprintf(stderr, "Optional arguments:\n");
-    fprintf(stderr, "   [-class_id class_id]     selects class_id (only used with -pixcenter)\n");
-    fprintf(stderr, "   [-astrom astrom.cmp] :   provide an alternative astrometry calibration\n");
-    fprintf(stderr, "   [-mask   mk_image] :     mask image\n");
-    fprintf(stderr, "   [-variance var_image] :  variance image\n");
-    fprintf(stderr, "   [-no_censor_masked] : do not set masked pixels to NAN\n");
+    fprintf(stderr, "   [-class_id class_id]  : selects class_id (only used with -pixcenter)\n");
+    fprintf(stderr, "   [-astrom astrom.cmp]  : provide an alternative astrometry calibration\n");
+    fprintf(stderr, "   [-mask   mk_image]    : mask image\n");
+    fprintf(stderr, "   [-variance var_image] : variance image\n");
+    fprintf(stderr, "   [-stage stage]        : stage of input image (raw, chip, warp, stack, diff)\n");
+    fprintf(stderr, "   [-write_jpeg]         : write a JPEG  format of the image stamp\n");
+    // fprintf(stderr, "   [-no_censor_masked]   : do not set masked pixels to NAN\n");
     fprintf(stderr, "\n");
 
@@ -84,4 +86,10 @@
         psArgumentRemove(argnum, &argc, argv);
     }
+    if ((argnum = psArgumentGet(argc, argv, "-write_jpeg"))) {
+        psArgumentRemove(argnum, &argc, argv);
+        options->writeJPEG = true;
+    } else {
+        options->writeJPEG = false;
+    }
 
     pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist");
Index: trunk/pstamp/src/ppstampOptions.h
===================================================================
--- trunk/pstamp/src/ppstampOptions.h	(revision 32370)
+++ trunk/pstamp/src/ppstampOptions.h	(revision 33378)
@@ -16,5 +16,5 @@
     psRegion    roi;            // roi in chip coordinates
     bool        censorMasked;
-
+    bool        writeJPEG;
 } ppstampOptions;
 
Index: trunk/pstamp/src/ppstampParseCamera.c
===================================================================
--- trunk/pstamp/src/ppstampParseCamera.c	(revision 32370)
+++ trunk/pstamp/src/ppstampParseCamera.c	(revision 33378)
@@ -8,5 +8,5 @@
 
 // Set up the ppstamp output Image file
-bool setupOutput(pmConfig *config, pmFPAfile *input, psString stage, bool doMask, bool doWeight)
+bool setupOutput(pmConfig *config, pmFPAfile *input, psString stage, bool doMask, bool doWeight, pmFPAfile **pOutput)
 {
     pmFPAfile *output;
@@ -22,4 +22,5 @@
         return false;
     }
+    *pOutput = output;
 
     output->save = true;
@@ -33,4 +34,5 @@
         outWeight->save = true;
     }
+
 
     return true;
@@ -76,5 +78,4 @@
         
 
-
     // XXX: create a filerule for PPSTAMP.ASTROM
     pmFPAfile *astrom = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM", "ASTROM");
@@ -95,10 +96,11 @@
 
     // Set up the output target
-    if (!setupOutput(config, input, options->stage, doMask, doWeight)) {
+    pmFPAfile *output;
+    if (!setupOutput(config, input, options->stage, doMask, doWeight, &output)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to setup output.");
         return false;
     }
 
-    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSTAMP.CHIP");
+    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSTAMP.CHIP");
     if (!chipImage) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPSTAMP.CHIP"));
@@ -108,4 +110,26 @@
         psError(PS_ERR_IO, true, "PPSTAMP.CHIP is not of type IMAGE");
         return NULL;
+    }
+
+    if (options->writeJPEG) {
+        char *filerule;
+        // If stage is chip flip the X axis otherwise don't flip.
+        // XXX: is this the right thing to do?
+        // Shouldn't the JPEG match the stamp even for chip stage?
+        if (!options->stage || strcmp(options->stage, "chip")) {
+            filerule = "PPSTAMP.OUTPUT.JPEG";
+        } else {
+            filerule = "PPSTAMP.OUTPUT.JPEG.FLIP";
+        }
+        pmFPAfile *jpg = pmFPAfileDefineOutput(config, output->fpa, filerule);
+        if (!jpg) {
+            psError(PS_ERR_IO, false, "Unable to generate new file from %s", filerule);
+            return NULL;
+        }
+        if (jpg->type != PM_FPA_FILE_JPEG) {
+            psError(PS_ERR_IO, true, "%s is not of type JPEG", filerule);
+            return NULL;
+        }
+        jpg->save = true;
     }
 
