python: create animated GIF

在Pillow包中提供了9种不同的图片模式,分别是1、L、P、RGBYCbCr、I、F,
模式 说明
l 二值图像,只有黑、白两种颜色
L 灰度图像
P 8位色彩图像
RGB 红、绿、蓝色彩空间,每一种颜色值在0~255内
RGBA 对图像增加透明通道
CMYK 四色标准颜色,一般用于打印品
YCbCr 色度和亮度分量标准,YCbCr是在计算机中应用最多的色彩标准
I 高清晰灰度标准,和L模式相比提供32位空间
F 灰度图像标准,保留转换后的浮点数
Pillow包提供了大量方便使用的图片处理工具,可以在官方文档中此API接口,地址为https://pillow.readthedocsio/en/stable/。

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: UTF-8 -*-
# encoding: utf-8
#-*- coding: UTF-8 -*-
# 版权所有 2023 ©涂聚文有限公司
# 许可信息查看:
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 311
# Datetime  : 2023/7/5 11:08
# User      : geovindu
# Product   : UI
# Project   : pythonTkinterDemo
# File      : menu.py
# explain   : 学习
 
from PIL import Image,ImageSequence
import glob
 
def makeGif(framefolder):
    """
    生成GIF动画图片
    :param framefolder: 文件夹
    :return:
    """
    images = glob.glob(f"{framefolder}/*.png")
    images.sort()
    frames = [Image.open(image) for image in images]
    frame_one = frames[0]
    print(frame_one)
    frame_one.save(framefolder+"/geovindu.gif", format="gif", append_images=frames,
                   save_all=True, duration=50, loop=0)

  

 

调用:

1
2
3
4
pathfolder = 'img_seq'
makeGif(pathfolder)
img=Image.open(pathfolder+"\geovindu.gif")
img.save()

  

from: Pillow (PIL Fork) 10.0.0 documentation

PEP8规范
www.python.org/dev/peps/
pip install autopep8

https://pillow.readthedocs.io/en/stable/

Comma-Separated Values CSV

 

https://www.blog.pythonlibrary.org/2021/06/29/converting-mp4-to-animated-gifs-with-python/
https://note.nkmk.me/en/python-pillow-gif/

 

posted @   ®Geovin Du Dream Park™  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2014-07-08 csharp: QR Code Barcode
2011-07-08 sql server 2005 输出表的函數用法
2011-07-08 SQL server 2005 表中某一字段的所有值逗号分开的列表
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示