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.
 
 

39 line
1.3 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, image_out):
  5. image = image_in.convert("RGBA")
  6. size = image.size
  7. center = (size[0]/2, size[1]/2)
  8. message = "YOU DIED"
  9. font_size = size[1] // 6
  10. gradient_range = size[1] // 10
  11. rect_top = sub(center, (0, font_size * 3 // 4))
  12. rect_bot = sub(center, (0, -font_size * 3 // 4))
  13. overlay = Image.new("RGBA", size, (0,0,0,0))
  14. draw = ImageDraw.Draw(overlay)
  15. font = ImageFont.truetype("OptimusPrinceps.ttf", font_size)
  16. draw.rectangle([0, rect_top[1], size[0], rect_bot[1]], fill=(0,0,0))
  17. for y in range(-1, -gradient_range - 1, -1):
  18. c = 255 - 255 * (-y) // gradient_range
  19. draw.line([0, rect_top[1] + y, size[0], rect_top[1] + y], fill=(0,0,0,c))
  20. for y in range(1, gradient_range + 1, 1):
  21. c = 255 - 255 * (y) // gradient_range
  22. draw.line([0, rect_bot[1] + y, size[0], rect_bot[1] + y], fill=(0,0,0,c))
  23. text_size = draw.textsize(message, font=font)
  24. offset = (center[0] - text_size[0]/2, center[1] - text_size[1]/2)
  25. draw.text(offset, message, (255,0,0), font=font)
  26. result = Image.alpha_composite(Image.alpha_composite(image, Image.new("RGBA", size, (0,0,0,100))), overlay)
  27. return result