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.

60 lines
1.8 KiB

  1. #!/usr/bin/env python3
  2. """
  3. Bootstraps a dark-mode icon for any light-mode icon
  4. """
  5. import argparse
  6. import os
  7. import re
  8. # These were quickly chosen as a good starting point based on checking contrast against
  9. # some light- and dark-mode window backgrounds taken from Ubuntu:
  10. # light mode: #FCFCFC
  11. # dark mode: #484848
  12. COLOR_MAP = {
  13. # "#ffffff": "#111111", # white
  14. # "#fff": "#111111", # white (short)
  15. "#333333": "#E0E0E0", # off black
  16. "#333": "#E0E0E0", # off black (short)
  17. "#545454": "#F4EFF3", # dark grey primary
  18. "#606060": "#F0EBF0", # dark grey large area
  19. "#909090": "#d0d0d0", # medium grey
  20. "#b9b9b9": "#8f8f8f", # light grey 1
  21. "#c1c1c1": "#999999", # light grey 2
  22. "#f3f3f3": "#545454", # off white 1
  23. "#f5f5f5": "#545454", # off white 2
  24. "#1A81C4": "#42B8EB", # primary blue
  25. "#39b4ea": "#1A81C4", # light blue
  26. "#bf2641": "#f2647e", # primary red
  27. }
  28. def process(src_dir, target_dir):
  29. for entry in os.scandir(src_dir):
  30. if entry.is_file() and entry.path.endswith(".svg"):
  31. processOne(os.path.abspath(entry.path), target_dir)
  32. def processOne(src, target_dir):
  33. #print('Processing {}'.format(src))
  34. with open(src, 'r') as f:
  35. svg = f.read()
  36. for key in COLOR_MAP.keys():
  37. expr = re.compile(r'({})'.format(key), re.I)
  38. svg = expr.sub(COLOR_MAP[key], svg)
  39. target_name = os.path.join(target_dir, os.path.basename(src))
  40. with open(target_name, 'w') as out:
  41. out.write(svg)
  42. print('Wrote {}'.format(target_name))
  43. if __name__ == '__main__':
  44. parser = argparse.ArgumentParser()
  45. parser.add_argument("source_dir")
  46. parser.add_argument("target_dir")
  47. args = parser.parse_args()
  48. process(args.source_dir, args.target_dir)