""" 挑帧,本程序把一个较大的gif文件,删除大部分帧,保留'关键帧'以减小gif文件尺寸。 经证明用imageio合并的gif文件仍较大,可以用其它软件如gifanimator打开后另存为 就更小了。关键词:拆帧/合帧/合并帧 """ import os import imageio from PIL import Image,ImageSequence def makegif(path,filename): """把png文件合成gif文件""" images = [] amount = len(os.listdir(path)) for i in range(amount): file = path + os.sep + str(i) + ".png" images.append(file) frames = [imageio.imread(image) for image in images] imageio.mimsave(filename, frames, 'GIF', duration=0.5) def pick_frame(inputgif,outgif,间隔数): """挑帧函数,遍历gif中的每一帧,挑些帧出来合成新的gif文件""" out_dir = 'out_dir' if os.path.exists(out_dir): for file in os.listdir(out_dir): os.remove(os.getcwd() + os.sep + out_dir + os.sep + file) else: os.mkdir(out_dir)需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
-
归档
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 8 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 3 月
- 2024 年 2 月
- 2023 年 11 月
- 2023 年 9 月
- 2023 年 6 月
- 2023 年 5 月
- 2023 年 4 月
- 2023 年 3 月
- 2023 年 2 月
- 2023 年 1 月
- 2022 年 12 月
- 2022 年 11 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 2 月
- 2022 年 1 月
- 2021 年 12 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 8 月
- 2021 年 7 月
- 2021 年 6 月
- 2021 年 5 月
- 2021 年 4 月
- 2021 年 3 月
- 2021 年 2 月
- 2021 年 1 月
- 2020 年 12 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 9 月
- 2020 年 8 月
- 2020 年 7 月
- 2020 年 6 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 3 月
- 2020 年 2 月
- 2020 年 1 月
- 2019 年 12 月
- 2019 年 11 月
- 2019 年 10 月
- 2019 年 9 月
- 2019 年 8 月
- 2019 年 7 月
- 2019 年 6 月
- 2019 年 5 月
- 2019 年 4 月
- 2019 年 3 月
- 2019 年 2 月
- 2018 年 3 月
- 2018 年 1 月
- 2017 年 9 月
- 2017 年 5 月
- 2017 年 1 月
-
功能