Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import subprocess
  5.  
  6. from PIL import Image, ImageDraw, ImageFont
  7.  
  8.  
  9. def getscreenresolution():
  10. cmd = ['xrandr']
  11. cmd2 = ['grep', '*']
  12. p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
  13. p2 = subprocess.Popen(cmd2, stdin=p.stdout, stdout=subprocess.PIPE)
  14. p.stdout.close()
  15.  
  16. resolution_string, junk = p2.communicate()
  17. resolution = resolution_string.split()[0]
  18. width, height = resolution.split('x')
  19. return int(width), int(height)
  20.  
  21.  
  22. def drawscreenbackround(width, height, text):
  23. img = Image.new("RGB", (width, height), "black")
  24. fnt = ImageFont.truetype('LiberationSans-Bold.ttf', 47)
  25.  
  26. d = ImageDraw.Draw(img)
  27. d.text((width / 2, height / 2), text, font=fnt, fill=(255, 255, 0))
  28.  
  29. img.save('image.png') # Path?
  30.  
  31.  
  32. if __name__ == "__main__":
  33. myhost = os.uname()[1]
  34.  
  35. res = getscreenresolution()
  36. drawscreenbackround(res[0], res[1], myhost)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement