脚本后续更新及迭代将由kkitDeploy项目代替
https://github.com/luckman666/kkitdeploy_server
请大家持续关注kkitDeploy
波哥的麦克风线依然没有到,那么我们今天还是简单写个小例子来制作gif动态图片。
先说明一下脚本的使用方式吧:
桌面上新建文件,将python脚本和要制作的静态图片放到文件夹下面。
类似这样:
然后配置脚本的文件目录:
OriginalData_path = ‘F:\老牛’
其实把图片放到别的目录中也行,这里波哥就图省事了都放在一起了。
然后执行脚本就会生成一个gif.gif的动图。大家可以用浏览器验证一下哦!
仓库位置:
https://github.com/luckman666/makeGif.git
脚本内容:
rom PIL import Image
import subprocess,re
OriginalData_path = 'F:\老牛'
def listDataPath():
cmd = 'dir ' + OriginalData_path.replace('/','\\')
files = subprocess.check_output(cmd,shell=True)
files = str(files, encoding = "GBK")
files = files.strip().split('\r\n')
regex = re.compile(r'.*\s(.+\.jpg).*')
listFiles = []
for path in files:
match = regex.match(path)
if match:
listFiles.append(OriginalData_path+'/'+match.group(1))
return listFiles
def main():
imgaeList = listDataPath()
num=0
images = []
for i in imgaeList:
num += 1
if num==1:
im = Image.open(i)
else:
images.append(Image.open(i))
im.save('gif.gif', save_all=True, append_images=images, loop=1, duration=1, comment=b"aaabb")
if __name__ == "__main__":
main()
只有30行代码,两个函数!主要采用Image模块将静态jpg图片组成gif动图。
脚本有个亮点:可以扫描windos指定文件夹下面指定后缀名的文件哦。
注意:文件夹请用中文!