Browse Source

added gif2bml.py

feature/balanceutils
Fr3deric 7 years ago
parent
commit
b494ef2f41
  1. 36
      generators/gif2bml.py

36
generators/gif2bml.py

@ -0,0 +1,36 @@
#!/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)
Loading…
Cancel
Save