import os from PIL import Image inputpath = "D:\\Program Files\\TEST\\pictures\\013" outpath = "E:\\picOutput\\013" fileNameStr = "013_" path2 = os.listdir(inputpath) for dirs in path2: path3 = os.path.join(inputpath,dirs) i = 1 pics = os.listdir(path3) for f in pics: s = "{0:04d}".format(i) new_name = fileNameStr + dirs + '_'+ s + ".bmp" if f.endswith(".bmp"): old_file = os.path.join(path3,f) new_file1 = os.path.join(outpath,dirs) new_file = os.path.join(new_file1,new_name) img = Image.open(old_file) cropped = img.crop((28, 24, 92, 96)) # (left, upper, right, lower) 左上,右下 if i==1: os.makedirs(new_file1) cropped.save(new_file) print("修改后:",format(new_file)) i +=1
图片自动裁剪的python实现
最新推荐文章于 2024-03-26 08:58:28 发布