11import datetime
2+ import warnings
3+ from collections .abc import Sequence
24from pathlib import Path
35from typing import Literal
4- from collections .abc import Sequence
5- from PIL import Image
6- import imageio
76
7+ import imageio
8+ from PIL import Image
9+ import nibabel as nib
810import numpy as np
911import numpy .typing as npt
10- import nibabel as nib
12+ from scipy .ndimage import center_of_mass
13+ from tqdm import tqdm
1114import plotly .graph_objects as go
1215import plotly .io as pio
1316from matplotlib .colors import LinearSegmentedColormap , to_hex
14- from scipy .ndimage import center_of_mass
15- from tqdm import tqdm
16-
1717from loguru import logger
1818
19+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
20+
1921Num = int | float
2022
2123__all__ = [
@@ -380,7 +382,6 @@ def create_gif_from_images(
380382 folder_path : str | Path ,
381383 output_name : str = "output.gif" ,
382384 fps : int = 10 ,
383- extensions : Sequence [str ] = (".png" , ".jpg" , ".jpeg" ),
384385) -> None :
385386 """
386387 从指定文件夹中的图片生成 GIF 文件。
@@ -389,13 +390,13 @@ def create_gif_from_images(
389390 folder_path (str | Path): 图片所在文件夹路径
390391 output_name (str, optional): 输出 GIF 文件名,默认为 "output.gif"
391392 fps (int, optional): GIF 帧率,默认为 10
392- extensions (Sequence[str], optional): 图片文件扩展名过滤,默认为 ('.png', '.jpg', '.jpeg')
393393 """
394394 folder = Path (folder_path )
395395 if not folder .exists () or not folder .is_dir ():
396396 raise ValueError (f"{ folder } 不是有效的文件夹路径。" )
397397
398398 # 获取文件夹下指定扩展名的文件,并排序
399+ extensions = (".png" , ".jpg" , ".jpeg" )
399400 figures_path = sorted (
400401 [f for f in folder .iterdir () if f .suffix .lower () in extensions ]
401402 )
@@ -409,8 +410,8 @@ def create_gif_from_images(
409410 output_path = folder / output_name
410411
411412 # 创建 GIF
412- with imageio .get_writer (output_path , mode = 'I' , fps = fps , loop = 0 ) as writer :
413+ with imageio .get_writer (output_path , mode = "I" , fps = fps , loop = 0 ) as writer :
413414 for figure in figures :
414- writer .append_data (figure .convert (' RGB' ))
415+ writer .append_data (figure .convert (" RGB" ))
415416
416- print (f"GIF 已保存到: { output_path } " )
417+ logger . info (f"GIF 已保存到: { output_path } " )
0 commit comments