make-msix-assets.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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: a round dark badge, so it needs no plate) and the
  5. project-file logo from the largest image in resources/LYNX_doc.ico. Scale and target-size variants follow
  6. Microsoft's tile/icon asset guidelines; makepri (in the release workflow) indexes them into resources.pri.
  7. """
  8. import os
  9. import sys
  10. from PIL import Image
  11. ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. OUT = os.path.join(ROOT, "resources", "msix", "Assets")
  13. SCALES = (100, 125, 150, 200, 400)
  14. TARGETS = (16, 20, 24, 30, 32, 36, 40, 48, 60, 64, 72, 80, 96, 256)
  15. def badge():
  16. return Image.open(os.path.join(ROOT, "resources", "lynx_badge.png")).convert("RGBA")
  17. def doc_icon():
  18. ico = Image.open(os.path.join(ROOT, "resources", "LYNX_doc.ico"))
  19. best = max(ico.info.get("sizes", {ico.size}), key=lambda s: s[0])
  20. ico.size = best
  21. return ico.convert("RGBA")
  22. def placed(src, width, height, fraction):
  23. """src scaled to `fraction` of the shorter side, centred on a transparent canvas."""
  24. side = max(1, round(min(width, height) * fraction))
  25. canvas = Image.new("RGBA", (width, height), (0, 0, 0, 0))
  26. icon = src.resize((side, side), Image.LANCZOS)
  27. canvas.alpha_composite(icon, ((width - side) // 2, (height - side) // 2))
  28. return canvas
  29. def save(img, name):
  30. img.save(os.path.join(OUT, name), optimize=True)
  31. def main():
  32. os.makedirs(OUT, exist_ok=True)
  33. for f in os.listdir(OUT):
  34. if f.endswith(".png"):
  35. os.remove(os.path.join(OUT, f))
  36. b, d = badge(), doc_icon()
  37. for s in SCALES:
  38. k = s / 100.0
  39. save(placed(b, round(44 * k), round(44 * k), 1.0), f"Square44x44Logo.scale-{s}.png")
  40. save(placed(b, round(150 * k), round(150 * k), 0.66), f"Square150x150Logo.scale-{s}.png")
  41. save(placed(b, round(310 * k), round(150 * k), 0.66), f"Wide310x150Logo.scale-{s}.png")
  42. save(placed(b, round(71 * k), round(71 * k), 0.8), f"SmallTile.scale-{s}.png")
  43. save(placed(b, round(310 * k), round(310 * k), 0.6), f"LargeTile.scale-{s}.png")
  44. save(placed(b, round(50 * k), round(50 * k), 1.0), f"StoreLogo.scale-{s}.png")
  45. save(placed(d, round(44 * k), round(44 * k), 1.0), f"ProjectFile.scale-{s}.png")
  46. for t in TARGETS:
  47. icon = placed(b, t, t, 1.0)
  48. for suffix in ("", "_altform-unplated", "_altform-lightunplated"):
  49. save(icon, f"Square44x44Logo.targetsize-{t}{suffix}.png")
  50. save(placed(d, t, t, 1.0), f"ProjectFile.targetsize-{t}.png")
  51. print(f"{len(os.listdir(OUT))} files in {OUT}")
  52. return 0
  53. if __name__ == "__main__":
  54. sys.exit(main())