首页 > 解决方案 > 在文件夹中创建新图像

问题描述

我是 python 的初学者,并试图为我的硕士论文实现一些东西。

我试图为我的图片添加黑色边框,但我的问题是我想为我的目录中的所有图片添加边框,/dataset/OldImages/0/*并生成带有黑色边框的新图片到目录/dataset/NewImages/0/

这是我所做的代码:

images = glob.glob('dataset/oldImages/0/*')
for i in images:
    img = Image.open(images)
    img_with_border = ImageOps.expand(img, border=70, fill='black')
    new_path('dataset/newImages/0')
    img_with_border.save(new path, 'png')

我收到此错误:

Traceback (most recent call last):
  File "/Users/mhmdysfrmzngl/PycharmProjects/Sign2Math2/imagePadding.py", line 21, in <module>
    img = Image.open(images)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2615, in open
    fp = io.BytesIO(fp.read())
AttributeError: 'list' object has no attribute 'read'

标签: pythonsaving-data

解决方案


推荐阅读