将一张图片贴到另一张图片上,代码如下:

from PIL import Image
import os
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
path = r'E:\work\taikang_shangtang\test5\1.35W/'
save_path = r'E:\work\taikang_shangtang\test5\1.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

 

相关文章:

  • 2022-01-10
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2021-08-09
  • 2022-02-15
  • 2022-01-14
相关资源
相似解决方案