浏览:45 留言:0
手机扫我访问

1159套GIF动态称号 PNG序列帧素材「支持GIF转换」

下面的python脚本直接输出(输出了webp缩略图)

相关标签:杂乱分类

1159套GIF动态称号 PNG序列帧素材「支持GIF转换」

AI
AI文摘 此内容由AI根据文章内容自动生成
AI Summary

预览,录屏的闪烁是本地渲染一次性加载太多的问题,非图标本身闪烁

下面的python脚本直接输出(输出了webp缩略图)

import os
from PIL import Image
from pathlib import Path

source_dir = "1000多套图标"
output_dir = "webp输出"

os.makedirs(output_dir, exist_ok=True)

for season in os.listdir(source_dir):
    season_path = os.path.join(source_dir, season)
    if not os.path.isdir(season_path):
        continue
    
    for icon_set in os.listdir(season_path):
        icon_set_path = os.path.join(season_path, icon_set)
        if not os.path.isdir(icon_set_path):
            continue
        
        images = []
        png_files = sorted([f for f in os.listdir(icon_set_path) if f.endswith('.png')])
        
        if not png_files:
            continue
        
        # 先找出所有图片裁剪后的最大尺寸
        max_width = 0
        max_height = 0
        temp_images = []
        for png_file in png_files:
            img_path = os.path.join(icon_set_path, png_file)
            img = Image.open(img_path).convert('RGBA')
            
            # 自动裁剪透明边缘
            bbox = img.getbbox()
            if bbox:
                img = img.crop(bbox)
            
            temp_images.append(img)
            max_width = max(max_width, img.width)
            max_height = max(max_height, img.height)
        
        # 创建正方形画布并居中放置
        max_side = max(max_width, max_height)
        for img in temp_images:
            canvas = Image.new('RGBA', (max_side, max_side), (0, 0, 0, 0))
            x = (max_side - img.width) // 2
            y = (max_side - img.height) // 2
            canvas.paste(img, (x, y), img)
            images.append(canvas)
        
        if images:
            output_filename = f"{season}_{icon_set}.webp"
            output_path = os.path.join(output_dir, output_filename)
            images[0].save(
                output_path,
                save_all=True,
                append_images=images[1:],
                duration=100,
                loop=0,
                lossless=True
            )
            print(f"已生成: {output_filename}")

print(f"\n转换完成!所有WebP已保存到 {output_dir} 文件夹")
© 版权声明
THE END
点赞7分享
及时反馈~ 抢沙发

请登录后发表评论

    暂无评论内容