将一张图片贴到另一张图片上,代码如下:
from PIL import Image import os from PIL import ImageFile ImageFile.LOAD_TRUNCATED_IMAGES = True path = r'E:work aikang_shangtang est51.35W/' save_path = r'E:work aikang_shangtang est51.35W_resize/' os.makedirs(save_path,exist_ok=True) for pic in os.listdir(path): jgz = Image.open(path + pic) img = Image.open("F:/temp/upload_pic/huabu.jpg") img.paste(jgz,(196,139)) img.save(save_path + pic)
其中:(196,139) 是位置。
ps:如果不加下面两行代码,可能会报错:OSError: image file is truncated (8 bytes not processed)
from PIL import ImageFile ImageFile.LOAD_TRUNCATED_IMAGES = True