Python简单制作GIF
# _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’ )
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341