You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
906 B

#!/usr/bin/env python3
import argparse
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import PIL.Image
DEPTH = 256
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Convert GIF animations to BML.'
)
parser.add_argument('input_file')
parser.add_argument('output_file')
args = parser.parse_args()
gif = PIL.Image.open(args.input_file)
dim = blup.frame.FrameDimension(gif.width, gif.height, DEPTH, 3)
anim = blup.animation.Animation(dim)
for i in range(gif.n_frames):
gif.seek(i)
gf = gif.convert('RGB')
f = blup.animation.AnimationFrame(dim, gf.info.get('delay', 100))
for x in range(dim.width):
for y in range(dim.height):
f.setPixel(x, y, gf.getpixel((x, y)))
anim.addFrame(f)
blup.writebml.writeBml(anim, args.output_file)