--- ImageParser.py.org	Thu Nov 22 15:19:28 2001
+++ ImageParser.py	Thu Nov 22 15:16:32 2001
@@ -53,8 +53,9 @@
 
         try:
             try:
-                self.convert_to_pnm(data, tmpfile)
-                self._doc.set_data(self.convert_to_Tbmp(tmpfile))
+                self.convert(data, tmpfile)
+                f = open(tmpfile, "rb")
+                self._doc.set_data(f.read())
             finally:
                 try: os.unlink(tmpfile)
                 except: pass
@@ -73,41 +74,7 @@
         return self._scaled
 
 
-    def convert_to_Tbmp(self, tmpfile):
-
-        ppmtoTbmp = self._config.get_string ('ppmtoTbmp_program', 'ppmtoTbmp')
-        if self._bpp == 2:
-            ppmtoTbmp = ppmtoTbmp + " -2bit"
-        elif self._bpp == 4:
-            ppmtoTbmp = ppmtoTbmp + " -4bit"
-
-        if self._verbose <= 1:
-            ppmtoTbmp = ppmtoTbmp + " -quiet"
-
-	outfile = tempfile.mktemp()
-
-        command = ppmtoTbmp + " " + tmpfile + " > " + outfile
-
-        if self._verbose > 1:
-            print "Running: ", command
-
-        try:
-            if os.system (command):
-                raise RuntimeError, "Error while executing command '%s'" % command
-            f = open (outfile, "rb")
-            data = f.read ()
-            f.close ()
-
-            if len (data) == 0:
-                # Oops, nothing fetched?!?
-                raise RuntimeError, "No data from parsing image! (%s)" % self._url
-        finally:
-            try: os.unlink(outfile) 
-            except: pass
-        return data
-
-
-    def convert_to_pnm(self, data, tmpfile):        
+    def convert(self, data, tmpfile):        
 
 	infile = tempfile.mktemp()
 
@@ -132,7 +99,7 @@
             pipe = os.popen(command)
             info = pipe.read()
             pipe.close()
-	    match = re.search(r"\s([0-9]+)x([0-9]+)\s", info)
+	    match = re.search(r"\s([0-9]+)x([0-9]+)\D", info)
 	    if not match:
 		raise RuntimeError, "Can't determine image size from output of ImageMagick 'identify' program:  " + info
 	    else:
@@ -143,19 +110,22 @@
                 self._scaled = 1
 		if self._verbose > 2: print '...image (natively %dx%d) must be scaled' % (mywidth, myheight)
 
-            size = "\"" + maxwidth + "x" + maxheight + ">\""
+            size = " -geometry \"" + maxwidth + "x" + maxheight + ">\" "
 
             if self._bpp == 1:
-                ncolors = "2"
+                ncolors = " -monochrome -dither "
+                format = " palm1:"
             elif self._bpp == 2:
-                ncolors = "4"
+                ncolors = " -colors 4 -dither "
+                format = " palm2:"
+            elif self._bpp == 4:
+                ncolors = " -colors 16 -dither "
+                format = " palm4:"
             else:
-                ncolors = "16"
-
-            if self._bpp == 1:
-                convert = convert + " -monochrome"
+                ncolors = " -colors 256 -dither "
+                format = " palm8:"
 
-            command = convert + " -colors " + ncolors + " -dither -geometry " + size + " " + infile +" ppm:" + tmpfile
+            command = convert + ncolors + size + infile + format + tmpfile
 
             if self._verbose > 1:
                 print "Running: ", command
