python 图片名称修改
def change_name():
import os
from PIL import Image
path = u'C:/Users/Administrator/Desktop/imgs/abc/abcd/' # 原始图片位置
newpath = u'C:/Users/Administrator/Desktop/new_imgs/' # 保存图片位置
filelists = os.listdir(path)
for line in filelists:
check = str(line)[-7:-4]
if int(check) < 100:
check = str(line)[-6:-4]
print check
img = Image.open(path + line)
out = 'normal_{}_10.png'.format(check)
img.save(newpath + out)
这段代码展示了如何使用Python的os和PIL库来批量处理图片文件名。它遍历指定目录下的文件,检查文件名中的数字部分,并将图片重命名为`normal_XX_10.png`的格式。
1万+

被折叠的 条评论
为什么被折叠?



