1-export.py 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. """
  3. Export spinner as GIF.
  4. Dependencies:
  5. - Python 3.5+
  6. - Inkscape
  7. """
  8. import subprocess
  9. import tempfile
  10. FRAMES = 30
  11. def create_png(rotation: int) -> None:
  12. with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8',
  13. prefix='threema-web-spinner-', suffix='.svg') as f:
  14. # Write rotated SVG to temporary file
  15. f.write(svg.replace('rotate(132,15,15)', 'rotate(%d,15,15)' % rotation))
  16. f.flush()
  17. # Convert to PNG
  18. filename = 'spinner-{:0>3}.png'.format(rotation)
  19. print('Creating %s...' % filename)
  20. result = subprocess.run([
  21. 'inkscape',
  22. '-z',
  23. '-e', filename,
  24. '-w', '30',
  25. '-h', '30',
  26. '-b', 'white',
  27. f.name,
  28. ])
  29. result.check_returncode()
  30. if __name__ == '__main__':
  31. with open('spinner.svg', 'r') as f:
  32. svg = f.read()
  33. for i in range(FRAMES):
  34. create_png(int(360 / FRAMES * i))