Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. from PIL import Image,ImageDraw,ImageFont
  2. import os
  3.  
  4. unt = 0
  5. rech = 0
  6. zeichen = ['@','#','S','%','?','!','*','+',';',':','.']
  7. size_300 =(1000,1000)
  8. filename = "imm.jpg"
  9.  
  10. image1 = Image.open(filename)
  11. fn, ftext = os.path.splitext(filename)
  12. image1.thumbnail(size_300)
  13. image1 = image1.convert(mode="L")
  14. liste_pix = list(image1.getdata())
  15. width, height = image1.size
  16.  
  17. filename = fn+"ascii"+ftext
  18. fnt = ImageFont.truetype('arial.ttf', 15)
  19. image = Image.new(mode = "RGB", size = (width*12,height*12), color = "white")
  20. draw = ImageDraw.Draw(image)
  21. for i in range(width*height):
  22. draw.text((rech*12,unt*12),zeichen[round(liste_pix[i]/25)], font=fnt, fill=(0,0,0))
  23. rech = rech +1
  24. if i % width == 0 and i != 0:
  25. rech = 0
  26. unt = unt+1
  27.  
  28. image.show()
  29. image.save("C:/Users/Tom/Documents/Python/Python/ascii_img/"+filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement