4
0

make_doc_icon.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Generates the LYNX project-file icon (a dark page with a folded corner, a red band and the LYNX badge).
  2. # Usage: python3 tools/make_doc_icon.py resources/lynx_icon_256.png resources/LYNX_doc.ico [preview.png]
  3. import sys
  4. from PIL import Image, ImageDraw, ImageFilter
  5. S = 1024
  6. badge = Image.open(sys.argv[1]).convert("RGBA")
  7. page = Image.new("RGBA", (S, S), (0, 0, 0, 0))
  8. left, right, top, bottom = 150, 874, 40, 984
  9. fold = 230
  10. outline = [(left, top), (right - fold, top), (right, top + fold), (right, bottom), (left, bottom)]
  11. # soft shadow under the page
  12. shadow = Image.new("RGBA", (S, S), (0, 0, 0, 0))
  13. ImageDraw.Draw(shadow).polygon([(x + 14, y + 20) for x, y in outline], fill=(0, 0, 0, 120))
  14. page = Image.alpha_composite(page, shadow.filter(ImageFilter.GaussianBlur(22)))
  15. body = Image.new("RGBA", (S, S), (0, 0, 0, 0))
  16. d = ImageDraw.Draw(body)
  17. d.polygon(outline, fill=(38, 38, 43, 255))
  18. # vertical sheen: lighter at the top
  19. sheen = Image.linear_gradient("L").resize((S, S)).point(lambda v: int(40 * (1 - v / 255)))
  20. light = Image.new("RGBA", (S, S), (255, 255, 255, 0))
  21. light.putalpha(sheen)
  22. mask = Image.new("L", (S, S), 0)
  23. ImageDraw.Draw(mask).polygon(outline, fill=255)
  24. light.putalpha(Image.composite(light.getchannel("A"), Image.new("L", (S, S), 0), mask))
  25. body = Image.alpha_composite(body, light)
  26. d = ImageDraw.Draw(body)
  27. # red band at the bottom (the accent colour)
  28. d.rectangle((left, bottom - 150, right, bottom), fill=(214, 40, 40, 255))
  29. d.rectangle((left, bottom - 150, right, bottom - 138), fill=(240, 80, 70, 255))
  30. # folded corner
  31. d.polygon([(right - fold, top), (right - fold, top + fold), (right, top + fold)], fill=(78, 78, 86, 255))
  32. d.line([(right - fold, top), (right, top + fold)], fill=(20, 20, 24, 255), width=6)
  33. # thin border
  34. d.line(outline + [outline[0]], fill=(90, 90, 98, 255), width=8, joint="curve")
  35. page = Image.alpha_composite(page, body)
  36. # the LYNX badge in the middle of the page
  37. size = 560
  38. b = badge.resize((size, size), Image.LANCZOS)
  39. page.alpha_composite(b, ((left + right - size) // 2, top + fold - 40))
  40. sizes = [16, 20, 24, 32, 40, 48, 64, 96, 128, 256]
  41. page.save(sys.argv[2], format="ICO", sizes=[(s, s) for s in sizes])
  42. if len(sys.argv) > 3:
  43. page.resize((256, 256), Image.LANCZOS).save(sys.argv[3])
  44. print("ok")