python opencv實現gif圖片分解的示例程式碼
阿新 • • 發佈:2020-01-09
案例:將和當前指令碼同目錄下的gif圖片分解成png圖片,並將分解後的圖片儲存到pics目錄下,將其從0開始命名。
GIF 動圖的分解可以利用 PIL模組的Image類來實現。
from PIL import Image import os """ 將一張GIF動圖分解到指定資料夾 src_path:要分解的gif的路徑 dest_path:儲存後的gif路徑 """ def gifSplit(src_path,dest_path,suffix="png"): img = Image.open(src_path) for i in range(img.n_frames): img.seek(i) new = Image.new("RGBA",img.size) new.paste(img) new.save(os.path.join(dest_path,"%d.%s" %(i,suffix))) gifSplit('tiga.gif',r'./pics')
分解並儲存後:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。