code: def png(contents, kvs):
      
      outfile = os.path.join(IMAGEDIR, sha(contents + str(kvs['staffsize'])))
      src = outfile + '.png'
      if not os.path.isfile(src):
          try:
              os.mkdir(IMAGEDIR)
              stderr.write('Created directory ' + IMAGEDIR + '\n')
          except OSError:
              pass
          ly2png(contents, outfile, kvs)
          stderr.write('Created image ' + src + '\n')
      return src
docs: Creates a png if needed.