4
0

make_logo.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Generates the LYNX icon (dark disc + pepper) from the pepper's transparent PNG.
  2. # Usage: python3 tools/make_logo.py resources/lynx_logo.png output_folder
  3. import sys
  4. from PIL import Image, ImageDraw, ImageFilter, ImageChops
  5. S = 1024
  6. out = sys.argv[2]
  7. pepper = Image.open(sys.argv[1]).convert("RGBA")
  8. pepper = pepper.crop(pepper.getbbox())
  9. def radial(size, inner, outer, center=(0.5, 0.42)):
  10. # radial gradient (centre slightly above: light from the top)
  11. import math
  12. img = Image.new("RGBA", (size, size))
  13. px = img.load()
  14. cx, cy = center[0] * size, center[1] * size
  15. maxd = size * 0.62
  16. for y in range(size):
  17. for x in range(size):
  18. t = min(1.0, math.hypot(x - cx, y - cy) / maxd)
  19. t = t * t
  20. px[x, y] = tuple(int(inner[i] + (outer[i] - inner[i]) * t) for i in range(4))
  21. return img
  22. big = S * 2 # supersample for smooth edges
  23. mask = Image.new("L", (big, big), 0)
  24. ImageDraw.Draw(mask).ellipse((40, 40, big - 40, big - 40), fill=255)
  25. disc = radial(big, (52, 52, 56, 255), (8, 8, 10, 255))
  26. badge = Image.new("RGBA", (big, big), (0, 0, 0, 0))
  27. badge.paste(disc, (0, 0), mask)
  28. # rim: thin ring with an orange->red gradient (the pepper's colours), stronger at the top
  29. rim = Image.new("RGBA", (big, big), (0, 0, 0, 0))
  30. d = ImageDraw.Draw(rim)
  31. for i, w in enumerate(range(0, 22)):
  32. a = int(230 * (1 - i / 22))
  33. d.ellipse((40 + i, 40 + i, big - 40 - i, big - 40 - i), outline=(232, 74, 28, a), width=1)
  34. rimGrad = Image.linear_gradient("L").resize((big, big)).point(lambda v: 255 - int(v * 0.65))
  35. rim.putalpha(ImageChops.multiply(rim.getchannel("A"), rimGrad))
  36. badge = Image.alpha_composite(badge, rim)
  37. # glass gloss on the top half
  38. gloss = Image.new("L", (big, big), 0)
  39. ImageDraw.Draw(gloss).ellipse((170, 70, big - 170, big * 0.52), fill=34)
  40. gloss = gloss.filter(ImageFilter.GaussianBlur(60))
  41. gl = Image.new("RGBA", (big, big), (255, 255, 255, 0)); gl.putalpha(ImageChops.multiply(gloss, mask))
  42. badge = Image.alpha_composite(badge, gl)
  43. # pepper: ~74% of the height, slightly tilted, with a shadow
  44. h = int(big * 0.74)
  45. w = int(pepper.width * h / pepper.height)
  46. p = pepper.resize((w, h), Image.LANCZOS).rotate(-14, resample=Image.BICUBIC, expand=True)
  47. px, py = (big - p.width) // 2 + 10, (big - p.height) // 2 + 12
  48. shadow = Image.new("RGBA", (big, big), (0, 0, 0, 0))
  49. sh = Image.new("RGBA", p.size, (0, 0, 0, 255)); sh.putalpha(p.getchannel("A").point(lambda a: int(a * 0.7)))
  50. shadow.paste(sh, (px + 26, py + 34), sh)
  51. shadow = shadow.filter(ImageFilter.GaussianBlur(28))
  52. shadow.putalpha(ImageChops.multiply(shadow.getchannel("A"), mask))
  53. badge = Image.alpha_composite(badge, shadow)
  54. layer = Image.new("RGBA", (big, big), (0, 0, 0, 0)); layer.paste(p, (px, py), p)
  55. badge = Image.alpha_composite(badge, layer)
  56. final = badge.resize((S, S), Image.LANCZOS)
  57. final.save(out + "/lynx_badge_1024.png")
  58. for s in [16, 20, 24, 32, 40, 48, 64, 96, 128, 256, 512]:
  59. final.resize((s, s), Image.LANCZOS).save(f"{out}/badge_{s}.png")
  60. print("ok")