ArcMap Crashes when running Python script using PIL

Discussion created by gezjames on Jun 8, 2012
Latest reply on Jun 11, 2012 by nahmed-esristaff
I am trying to run a script that generates a number of down sampled images from source images in a given folder.  I am using the Python Imaging Library (PIL) for this and the code appears to crash on the line where the output image is saved.  I have put a try/catch statement in to get more information but the process appears to crash so it doesn't even get to the error message.  The code looks like the following:

import os, glob, arcpy
import Image

pth = arcpy.GetParameterAsText(0)
sep = arcpy.GetParameterAsText(1)
extarr = sep.split(".")
ext = extarr[len(extarr)-1]
sze_w = arcpy.GetParameterAsText(2)
sze_h = arcpy.GetParameterAsText(3)
arcpy.AddMessage("Got arguments!")
for (root, dirs, files) in os.walk(pth):
     for fle in files:
         if fle.endswith(ext):
             fullfle = os.path.join(root,fle)
             img =
##             img.MAXBLOCK = 1024*1024
             size = sze_w,sze_h
             img.thumbnail(size, Image.ANTIALIAS)
             oset = -1 * len(sep)
             f = fle[:oset]
             fullf = os.path.join(root, f + ".thumbnail.jpg")
##             arcpy.AddMessage(fullf + " created!")
        , "PNG")
             except Exception as e:
             arcpy.AddMessage(fullf + " created!")
##             #print fullf + " created!"
             del img

I should also mention that the code works just fine when run from the Python command line. 

Does anyone have any ideas why this is happening?

Thanks in advance
Gerry James
Geomatics Manager
Hatfield Consultants Partnership