我需要能够对来自同一文件夹的多个图像执行此操作。
答案 0 :(得分:0)
您可以使用:
import glob, os
os.chdir("/")
for infile in glob.glob("*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
add_border(im)
import Image
def add_border(im):
old_im = im
old_size = old_im.size
new_size = (800, 800)
new_im = Image.new("RGB", new_size) ## luckily, this is already black!
new_im.paste(old_im, ((new_size[0]-old_size[0])/2,(new_size[1]-old_size[1])/2))
new_im.show()
# new_im.save('someimage.jpg')
@credits: