python - 在文件夹中创建新图像
问题描述
我是 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'
解决方案
推荐阅读
- javascript - 如何用 JavaScript 中的正则表达式捕获组替换整个字符串?
- java - int[] 如何被接受为通用类型参数而不是 int?
- google-apps-script - 为什么某些由带有表单提交触发器的 Google Apps 脚本发送的电子邮件会发送两次?
- build - 嵌入式领域中的“构建系统”是什么?
- c# - 尝试在 C# 中对具有多个线程的数组进行排序时出现问题
- python - 函数调用另一个函数
- android - 动态 URL PDF 在 WebView 中显示为“无可用预览”
- firebase - 如何使用 Flutter 获取 Firestore 中嵌套项目的数量
- xamarin - 如何在 iOS 上的 WKWebView 中启用视频自动播放
- javascript - google.script.run 在文件输入的情况下失败