Last active
June 2, 2021 02:42
-
-
Save DIYer22/525e8f066e102dff2455fb6ee44a010d to your computer and use it in GitHub Desktop.
Merge multi GIF pictures into one GIF with Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Merge multi GIF pictures into one GIF. | |
requirement: | |
pip install boxx>=0.9.1 | |
@author: DIYer22@github | |
""" | |
gif_paths = ['loga','show','tree',] # the gif paths without `.gif` | |
fps = 24 | |
spatial_down_sample = 1 | |
time_down_sample = 1 | |
from boxx import * | |
from boxx.ylimg.ylimgVideoAndGif import * | |
a=0 | |
a=1 | |
if a: | |
gifs = [] | |
for pp in gif_paths: | |
gif = imread(pp+'.gif')[::] | |
gifs += [gif] | |
# break | |
ss = npa(map(x_.shape, gifs)) | |
print(ss) | |
#else: | |
fs = ss[:,0] | |
shape = ss.max(0)[[1, 2]] | |
news = [] | |
for i,gif in enumerate(gifs): | |
n , w, h, c = gif.shape | |
print('%sth GIF has'%i,n,'pics') | |
new = np.zeros((n, *shape, c), np.uint8) | |
new[:,:w,:h,:] = gif | |
news.extend(new) | |
news.extend(np.zeros((3, *shape, c), np.uint8)) | |
newgif = npa-news | |
print('save to merged_one.gif....') | |
gifSave(newgif[::time_down_sample,::spatial_down_sample,::spatial_down_sample,::],'merged_one.gif',fps) | |
print('OK') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got same error here