Skip to content

Commit 8cd30d1

Browse files
authored
Add files via upload
1 parent 29105f6 commit 8cd30d1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

script/gif_process.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
from PIL import Image,ImageSequence
22
import cv2
3-
import numpy as np
43

54
import re
65
from pixel_transform import *
6+
from tqdm import tqdm
77

88
def gif_edit(path, k=16, scale=1, blur=0, erode=0, alpha = True, to_tw = False, dither=False, saturation=0, contrast=0):
99
gif = Image.open(path)
10+
11+
gif_length = gif_find_length(gif)
12+
process = tqdm(total=gif_length)
13+
14+
duration = gif.info['duration']
1015
path.replace('\\', '/')
1116
file_name = re.split("/|\.", path)[-2]
1217
file_locat = path.split(file_name + '.gif')[0]
1318

1419
img_list = []
1520
for frame in ImageSequence.Iterator(gif):
21+
process.update(1)
1622
# frame = frame.convert('RGBA')
1723
# opencv_img = np.array(frame, dtype=np.uint8)
1824
# opencv_img = cv2.cvtColor(opencv_img, cv2.COLOR_RGBA2BGRA)
@@ -37,7 +43,7 @@ def gif_edit(path, k=16, scale=1, blur=0, erode=0, alpha = True, to_tw = False,
3743

3844
# save as gif
3945
# output[0].save(file_locat + file_name + 'edited' + ".gif", save_all=True, append_images=output[1:], duration=200, loop=0, disposal=0)
40-
output[0].save(file_name + 'edited' + ".gif", save_all=True, append_images=output[1:], duration=100, loop=0, disposal=0)
46+
output[0].save(file_name + 'edited' + ".gif", save_all=True, append_images=output[1:], duration=duration, loop=0, disposal=0)
4147
return img_list[0]
4248

4349
def show_gif(img_list):
@@ -49,4 +55,13 @@ def show_gif(img_list):
4955
if cv2.waitKey(200) == ord('q'):
5056
loop = False
5157
break
52-
cv2.destroyAllWindows()
58+
cv2.destroyAllWindows()
59+
60+
def gif_find_length(gif):
61+
try:
62+
while 1:
63+
gif.seek(gif.tell()+1)
64+
# do something to im
65+
except EOFError:
66+
pass # end of sequence
67+
return gif.tell()

0 commit comments

Comments
 (0)