批量将gif转png

---

from PIL import Image
import os
 
dirStr = 'D:/icon'
for file in os.listdir(dirStr):
    if file.lower().endswith('.gif'):
        gif = Image.open(dirStr + '/' + file)
        base = os.path.splitext(file)
        try:            
          gif.seek(0)
          frame = gif.copy()
          frame.save(dirStr + '/' + base[0]+ '.png')
        except EOFError:
            pass
        print(f'{file} finish')

---

posted @ 2026-11-08 08:42  ParamousGIS  阅读(8)  评论(0)    收藏  举报