A bot that overlays the "you died" text on stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

  1. from PIL import Image, ImageDraw, ImageFont
  2. def sub(p1, p2):
  3. return (p1[0] - p2[0], p1[1] - p2[1])
  4. def overlay(image_in):
  5. image = image_in.convert("RGBA")
  6. size = image.size
  7. center = (size[0]/2, size[1]/2)
  8. message = "YOU DIED"
  9. limit = size[1]
  10. if size[0] / size[1] < 1:
  11. limit = int(limit * size[0] / size[1])
  12. font_size = limit // 5
  13. gradient_range = limit // 10
  14. rect_top = sub(center, (0, font_size * 3 // 5))
  15. rect_bot = sub(center, (0, -font_size * 3 // 5))
  16. overlay = Image.new("RGBA", size, (0,0,0,0))
  17. draw = ImageDraw.Draw(overlay)
  18. font = ImageFont.truetype("OptimusPrinceps.ttf", font_size)
  19. draw.rectangle([0, rect_top[1], size[0], rect_bot[1]], fill=(0,0,0, 225))
  20. for y in range(-1, -gradient_range - 1, -1):
  21. c = 225 - 225 * (-y) // gradient_range
  22. draw.line([0, rect_top[1] + y, size[0], rect_top[1] + y], fill=(0,0,0,c))
  23. for y in range(1, gradient_range + 1, 1):
  24. c = 225 - 225 * (y) // gradient_range
  25. draw.line([0, rect_bot[1] + y, size[0], rect_bot[1] + y], fill=(0,0,0,c))
  26. text_size = draw.textsize(message, font=font)
  27. offset = (center[0] - text_size[0]/2, center[1] - text_size[1]/2)
  28. draw.text(offset, message, (200,25,25), font=font)
  29. result = Image.alpha_composite(Image.alpha_composite(image, Image.new("RGBA", size, (0,0,0,125))), overlay)
  30. return result