from PIL import Image def format(filePath): print "format...."+filePath oldImg = Image.open(filePath) x, y = oldImg.size maxSize = max(x, y) newIm = Image.new(oldImg.mode, (maxSize,maxSize), "WHITE") newIm.paste(oldImg, ((maxSize-x)/2, (maxSize-y)/2)) newIm.save(filePath) if __name__ == '__main__': pass