diff --git a/slidegtk.py b/slidegtk.py
index 07ba241c49843ff6e8450f0120d9c25ac1fb8ee0..b3c49b9635f49ab18f998f1654d71dcee0f34463 100755
--- a/slidegtk.py
+++ b/slidegtk.py
@@ -5,6 +5,7 @@ import os
 import sys
 import time
 import getopt
+import commands
 
 import pygtk
 pygtk.require('2.0')
@@ -30,7 +31,8 @@ class ImageCache(object):
 
     def processed_file(self, infile, rotation = 0):
         if rotation == 0:
-            fp = os.popen("identify -format \"%w %h\" " + infile)
+            fp = os.popen("identify -format \"%w %h\""
+                          + commands.mkarg(infile))
             words = fp.read().split()
             fp.close()
             w = int(words[0])
@@ -51,12 +53,15 @@ class ImageCache(object):
 	    if rotation == 0:
 		os.system("djpeg %s"
 			  "|pnmscale -xysize %s %s|cjpeg -optimize > %s" % (
-			infile, self.width, self.height, fn))
+                              commands.mkarg(infile), self.width, self.height,
+                              commands.mkarg(fn)))
 	    else:
 		os.system("jpegtran -rotate %s %s"
 			  "|djpeg"
 			  "|pnmscale -xysize %s %s|cjpeg -optimize > %s" % (
-		    rotation, infile, self.width, self.height, fn))
+                              rotation, commands.mkarg(infile),
+                              self.width, self.height,
+                              commands.mkarg(fn)))
 	return fn
 
     def hint(self, infile, rotation = 0):