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’ )
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制作简单的图形界面GUI
- Python简单的制作图片验证码实例
- Photoshop制作简单粗暴可爱的漫画GIF动画
- 用Adobe ImageReady制作简单GIF动画
- python3.6 简单爬虫爬取天气,flask在线查询接口制作
- Python3 网易有道词典结合PyInstaller,tkinter制作一个简单的中英文翻译exe文件
- 如何用Python来制作简单的爬虫,爬取到你想要的图片
- photoshop简单制作绚丽的gif动态图
- python-nmap模块的使用及制作一个简单的端口扫描器
- python小应用之moviepy的视频剪辑制作gif图
- Python制作一个简单的刷空间利器
- 用Python和摄像头制作简单的延时摄影
- 使用 Easy GIF Animator 6 Pro制作一张简单的GIF图
- 操作Windows注册表的简单的Python程序制作教程
- Python学习第三天(一个简单制作导入模块)
- 【python】简单爬虫制作(汽车之家&易车网报价爬虫)
- python运用jieba和wordcloud库简单实现对QQ聊天记录制作词云
- iOS中GIF的制作的简单版本记录
- Python简单安装包制作