code: def makeThumb(self, imagepath, thumbpath, tsize, img=None):
          
          try:
              # open image if needed
              if not img:
                  img = PIL.Image.open(imagepath)
              # do we need a thumbnail at all, or can the image be inlined?
              width, height = img.size
              factor = max(width / float(tsize[0]), height / float(tsize[1]))
              if factor <= 1:
                  return imagepath
              # generate the thumbnail
              img = img.resize((int(width / factor), int(height / factor)), PIL.Image.ANTIALIAS)
              img.save(thumbpath, "PNG")
              return thumbpath
          except:
              print("Error rendering thumbnail %s" % thumbpath)
              traceback.print_exc()
              return None
docs: makes a thumbnail for the given image.
          imagepath refers to an image file
          img can be an open PIL.Image -- if None, then imagepath is opened
          tsize is a width,height tuple giving the max thumbnail size
          extension is the extension of the thumbnail file