前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python简单制作GIF

Python简单制作GIF

作者头像
py3study
发布2020-01-10 17:33:35
6640
发布2020-01-10 17:33:35
举报
文章被收录于专栏:python3python3

# _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’ )

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档