from PIL import Image import os mapfile = "C:\\Users\\Administrator\\Desktop\\1.wmf" im = Image.open(mapfile) path = str(os.path.dirname(mapfile)) onlyfilename, ext = os.path.splitext(os.path.basename(mapfile)) str_onlyfilename = str(onlyfilename) im.save(path + '\\'+ str_onlyfilename + '.png', quality=95)