1.0.2 更新 4.9.7 + 图片刷新
This commit is contained in:
34
logo/yuantu/gif_zip.py
Normal file
34
logo/yuantu/gif_zip.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
from PIL import Image, ImageSequence
|
||||
#pip install pillow
|
||||
def resize_gif(input_path, output_path, width, height):
|
||||
"""按指定宽高重生成 GIF(保持多帧)"""
|
||||
img = Image.open(input_path)
|
||||
|
||||
frames = []
|
||||
for frame in ImageSequence.Iterator(img):
|
||||
frame = frame.convert("RGBA")
|
||||
frame = frame.resize((width, height), Image.Resampling.LANCZOS)
|
||||
frames.append(frame)
|
||||
|
||||
# 保存为 GIF
|
||||
frames[0].save(
|
||||
output_path,
|
||||
save_all=True,
|
||||
append_images=frames[1:],
|
||||
duration=img.info.get("duration", 100),
|
||||
loop=img.info.get("loop", 0),
|
||||
disposal=2,
|
||||
transparency=img.info.get("transparency")
|
||||
)
|
||||
print(f"生成成功: {output_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
width = 100 # 你想要的宽
|
||||
height = 100 # 你想要的高
|
||||
|
||||
for file_name in os.listdir("."):
|
||||
if file_name.lower().endswith(".gif"):
|
||||
output_name = f"new/{file_name}"
|
||||
resize_gif(file_name, output_name, width, height)
|
||||
Reference in New Issue
Block a user