less copy protection, more size visualization
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

82 Zeilen
3.5 KiB

  1. import sys
  2. import re
  3. import json
  4. import glob
  5. import os
  6. import subprocess
  7. import pathlib
  8. # an affront to god
  9. def combine(base_path, highlight_path, vivid_path, output_path):
  10. base = open(base_path, "r", encoding="utf-8").read()
  11. highlight = open(highlight_path, "r", encoding="utf-8").read()
  12. vivid = open(vivid_path, "r", encoding="utf-8").read()
  13. base_data = re.search("<g.*", base, flags=re.DOTALL)[0][:-7]
  14. highlight_data = re.search("<g.*", highlight, flags=re.DOTALL)[0][:-7]
  15. vivid_data = vivid.replace("</metadata>", "</metadata>" + base_data + "\n" + highlight_data)
  16. with open(output_path, "w", encoding="utf-8") as f:
  17. f.write(vivid_data)
  18. subprocess.run([INKSCAPE, "--without-gui", "--export-plain-svg=" + output_path.resolve().__str__(), "--export-area-drawing", output_path], shell=True)
  19. configdir = pathlib.Path(__file__).parent
  20. configpath = configdir.joinpath("config.json")
  21. config = json.load(open(configpath, encoding="utf-8"))
  22. workdir = pathlib.Path(config["work-directory"])
  23. sourcedir = workdir.joinpath(sys.argv[1])
  24. macrodir = pathlib.Path(config["macrovision-directory"])
  25. print(sourcedir, macrodir)
  26. side_strings = []
  27. POTRACE = config["potrace"]
  28. INKSCAPE = config["inkscape"]
  29. output = {}
  30. with open(sourcedir.joinpath("data.json"), "r", encoding="utf-8") as file:
  31. all_data = json.load(file)
  32. group_name = all_data["name"]
  33. category = all_data["kind"]
  34. outputdir = macrodir.joinpath("media").joinpath(category).joinpath(group_name)
  35. os.makedirs(outputdir, exist_ok=True)
  36. base_lut = configdir.joinpath("luts").joinpath("base-lut.png").__str__()
  37. highlight_lut = configdir.joinpath("luts").joinpath("highlight-lut.png").__str__()
  38. vivid_lut = configdir.joinpath("luts").joinpath("vivid-lut.png").__str__()
  39. for data in all_data["forms"]:
  40. name = data["name"]
  41. for view in data["views"]:
  42. view_name = view["name"]
  43. input = sourcedir.joinpath(name + "-" + view_name + ".png")
  44. result = outputdir.joinpath(name + "-" + view_name + ".svg")
  45. print(result)
  46. if os.path.exists(result) and os.path.getmtime(input) < os.path.getmtime(result):
  47. print("Skipping ", input)
  48. # continue
  49. input_base = sourcedir.joinpath(name + "-" + view_name + "-base.bmp")
  50. input_highlight = sourcedir.joinpath(name + "-" + view_name + "-highlight.bmp")
  51. input_vivid = sourcedir.joinpath(name + "-" + view_name + "-vivid.bmp")
  52. subprocess.run(["convert", input, base_lut, "-channel", "RGB", "-clut", "-background", "#FFFFFF", "-flatten", input_base], shell=True)
  53. subprocess.run(["convert", input, highlight_lut, "-channel", "RGB", "-clut", "-background", "#FFFFFF", "-flatten", input_highlight], shell=True)
  54. subprocess.run(["convert", input, vivid_lut, "-channel", "RGB", "-clut", "-background", "#FFFFFF", "-flatten", input_vivid], shell=True)
  55. output_base = sourcedir.joinpath(name + "-" + view_name + "-base.svg")
  56. output_highlight = sourcedir.joinpath(name + "-" + view_name + "-highlight.svg")
  57. output_vivid = sourcedir.joinpath(name + "-" + view_name + "-vivid.svg")
  58. subprocess.run([POTRACE, input_base, "-b", "svg", "-o", output_base], shell=True)
  59. subprocess.run([POTRACE, input_highlight, "-b", "svg", "-C", "#1a1a1a", "-o", output_highlight], shell=True)
  60. subprocess.run([POTRACE, input_vivid, "-b", "svg", "-C", "#333333", "-o", output_vivid], shell=True)
  61. combine(output_base, output_highlight, output_vivid, result)
  62. # os.unlink(input_base)
  63. # os.unlink(input_highlight)