python實現圖片批量剪裁的程序


 1 from PIL import Image
 2 import os
 3 fin = 'D:/test'
 4 fout = 'D:/test2'
 5 for file in os.listdir(fin):
 6     file_fullname = fin + '/' +file
 7     img = Image.open(file_fullname)
 8     a = [80, 100, 260, 300]
 9     box = (a)
10     roi = img.crop(box)
11     if fout not in os.listdir('D:/'):
12         os.mkdir(fout)
13     out_path = fout + '/' + file
14     roi.save(out_path)

基礎不好,花樣踩坑,在此記錄一下。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM