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') |
你好 运行上面代码报错如下:
Traceback (most recent call last):
[[306 320 4]
[469 360 4]
File "XXXXXX/combine.py", line 27, in
[330 272 4]]
n , w, h, c = gif.shape
ValueError: not enough values to unpack (expected 4, got 3)
try to put r before the path string. r"C:\Users\username......"
got same error here
[[2100 1500 4]
[2100 1500 4]]
Traceback (most recent call last):
File "gif.py", line 37, in <module>
n, w, h, c = gif.shape
ValueError: not enough values to unpack (expected 4, got 3)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好 运行上面代码报错如下:
Traceback (most recent call last):
[[306 320 4]
[469 360 4]
File "XXXXXX/combine.py", line 27, in
[330 272 4]]
n , w, h, c = gif.shape
ValueError: not enough values to unpack (expected 4, got 3)