您的位置:首页 > 编程语言 > Python开发

Python简单制作GIF

2017-12-25 15:41 609 查看
# _author_ == ‘ljh’

import imageio

import glob

import re

from PIL import Image, ImageDraw, ImageFont, ImageColor

# modify the size of the images

def change():

old_img_filenames = glob.glob(r’C:\Users\Jack\Desktop\old*.jpg’)

widthlist = []

heightlist = []

for img_names in old_img_filenames:

img = Image.open(img_names)

width, height = img.size

widthlist.append(width)

heightlist.append(height)

widthlist.sort()

heightlist.sort()

width_min = widthlist[0]

height_min = heightlist[0]

for i,j in enumerate(old_img_filenames):

img = Image.open(j)

out = img.resize((width_min,height_min),Image.ANTIALIAS)

out.save(r’C:\Users\Jack\Desktop\new\%s.jpg’%str(i),’jpeg’)

# look for all images needed

def find_all_png():

png_filenames = glob.glob(r’C:\Users\Jack\Desktop\old*.jpg’)

buf=[]

for png_file in png_filenames:

buf.append(png_file)

return buf

#make images into a gif

def create_gif(image_list, gif_name):

frames = []

for image_name in image_list:

frames.append(imageio.imread(image_name))

# Save them as frames into a gif

imageio.mimsave(gif_name, frames, ‘GIF’, duration = 0.8)

if name == ‘main‘:

# change()

# buff = find_all_png()

# create_gif(buff,r’C:\Users\Jack\Desktop\xinxin.gif’ )
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python