python下批量修改图片格式和大小
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python下批量修改图片格式和大小
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            第一種方法用到opencv庫
import os
import timeimport cv2def alter(path,object):result = []s = os.listdir(path)count = 1
    for i in s:document = os.path.join(path,i)img = cv2.imread(document)img = cv2.resize(img, (20,20))listStr = [str(int(time.time())), str(count)]fileName = ''.join(listStr)cv2.imwrite(object+os.sep+'%s.jpg' % fileName, img)count = count + 1
alter('D:\\new\\ren\\test','D:\\new\\ren\\object')第二種方法用到PIL庫
import os
import time
from PIL import Imagedef alter(path,object):s = os.listdir(path)count = 1
    for i in s:document = os.path.join(path,i)img = Image.open(document)out = img.resize((20,20))listStr = [str(int(time.time())), str(count)]fileName = ''.join(listStr)out.save(object+os.sep+'%s.jpg' % fileName)count = count + 1
alter('D:\\new\\ren\\new','D:\\new\\ren\\new1')
                            
                        
                        
                        總結
以上是生活随笔為你收集整理的python下批量修改图片格式和大小的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: NodeJS + WebStorm 中
- 下一篇: C语言有符号和无符号数
