make-msix-assets.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. """Writes the MSIX (Microsoft Store) image assets to resources/msix/Assets from LYNX's icon (round 165n).
  3. Usage: scripts/make-msix-assets.py (needs Pillow; the PNGs are committed, so a release build does not run this)
  4. Every logo comes from resources/lynx_badge.png (the app icon: the LYNX SHARE logo by w3teal on its own dark tile, so it
  5. needs no plate; written by tools/make_logo.py), the 16-32 px icons from its small-size form
  6. resources/brand/lynx-share-logo-small.png (20 px and less without the stem: lynx-share-logo-tiny.png), and the
  7. project-file logo from the largest image in resources/LYNX_doc.ico. Scale and target-size variants follow
  8. Microsoft's tile/icon asset guidelines; makepri (in the release workflow) indexes them into resources.pri.
  9. """
  10. import os
  11. import sys
  12. from PIL import Image
  13. ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  14. OUT = os.path.join(ROOT, "resources", "msix", "Assets")
  15. SCALES = (100, 125, 150, 200, 400)
  16. TARGETS = (16, 20, 24, 30, 32, 36, 40, 48, 60, 64, 72, 80, 96, 256)
  17. def badge():
  18. return Image.open(os.path.join(ROOT, "resources", "lynx_badge.png")).convert("RGBA")
  19. def small_badge(name):
  20. return Image.open(os.path.join(ROOT, "resources", "brand", name)).convert("RGBA")
  21. def doc_icon():
  22. ico = Image.open(os.path.join(ROOT, "resources", "LYNX_doc.ico"))
  23. best = max(ico.info.get("sizes", {ico.size}), key=lambda s: s[0])
  24. ico.size = best
  25. return ico.convert("RGBA")
  26. def placed(src, width, height, fraction):
  27. """src scaled to `fraction` of the shorter side, centred on a transparent canvas."""
  28. side = max(1, round(min(width, height) * fraction))
  29. canvas = Image.new("RGBA", (width, height), (0, 0, 0, 0))
  30. icon = src.resize((side, side), Image.LANCZOS)
  31. canvas.alpha_composite(icon, ((width - side) // 2, (height - side) // 2))
  32. return canvas
  33. def save(img, name):
  34. img.save(os.path.join(OUT, name), optimize=True)
  35. def main():
  36. os.makedirs(OUT, exist_ok=True)
  37. for f in os.listdir(OUT):
  38. if f.endswith(".png"):
  39. os.remove(os.path.join(OUT, f))
  40. b, d = badge(), doc_icon()
  41. sb, tb = small_badge("lynx-share-logo-small.png"), small_badge("lynx-share-logo-tiny.png")
  42. for s in SCALES:
  43. k = s / 100.0
  44. save(placed(b, round(44 * k), round(44 * k), 1.0), f"Square44x44Logo.scale-{s}.png")
  45. save(placed(b, round(150 * k), round(150 * k), 0.66), f"Square150x150Logo.scale-{s}.png")
  46. save(placed(b, round(310 * k), round(150 * k), 0.66), f"Wide310x150Logo.scale-{s}.png")
  47. save(placed(b, round(71 * k), round(71 * k), 0.8), f"SmallTile.scale-{s}.png")
  48. save(placed(b, round(310 * k), round(310 * k), 0.6), f"LargeTile.scale-{s}.png")
  49. save(placed(b, round(50 * k), round(50 * k), 1.0), f"StoreLogo.scale-{s}.png")
  50. save(placed(d, round(44 * k), round(44 * k), 1.0), f"ProjectFile.scale-{s}.png")
  51. for t in TARGETS:
  52. icon = placed(tb if t <= 20 else sb if t <= 32 else b, t, t, 1.0)
  53. for suffix in ("", "_altform-unplated", "_altform-lightunplated"):
  54. save(icon, f"Square44x44Logo.targetsize-{t}{suffix}.png")
  55. save(placed(d, t, t, 1.0), f"ProjectFile.targetsize-{t}.png")
  56. print(f"{len(os.listdir(OUT))} files in {OUT}")
  57. return 0
  58. if __name__ == "__main__":
  59. sys.exit(main())