Python

Python 学习记录2

2017-12-26  本文已影响0人  夏秋之萌

多图合成gif图片 (PIL)

from PIL import Image
import os,imageio,re

dir = r"C:\Users\xxxx\Desktop\Python\example"
imglist = []
for d in os.listdir(dir):
    imglist.append(dir + '\\' + d)
#对所有图片进行resize,并保存
for i in imglist:
    f,ext = os.path.splitext(i)
    img = Image.open(i)
    img = img.resize((300,200))
    img.save(f + "_thumbnail.jpg","JPEG")
images = []
for i in os.listdir(dir):
    if "thumbnail" in i:
        print(i,Image.open(dir+'\\'+i).size)
        images.append(Image.open(dir + '\\' + i))

##打开一张图片作为初始图片
im=Image.open(r"C:\Users\xxxx\Desktop\Python\example\0_thumbnail.jpg")
im.save('all.gif',save_all=True,append_images=images,loop=1,duration=2)
上一篇下一篇

猜你喜欢

热点阅读