Advertisement
Guest User

File to PIc

a guest
Sep 27th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import sys
  2. import math
  3. import os.path
  4. import io
  5. import PIL
  6. from PIL import Image, ImageDraw
  7.  
  8. input_dir = r"C:\Users\Andrew\Desktop\\"
  9. input_file = r"SPeech.docx"
  10. input_full = input_dir + "" + input_file
  11.  
  12. f = open(input_full, "rb")
  13. ba = bytearray(f.read())
  14. f_Size = len(ba)
  15.  
  16. width = int(round(math.sqrt(f_Size),0))
  17. height = int(round((f_Size) / width,0) - 1)
  18.  
  19. comp = Image.new("RGB", (width, height), "white")
  20. d = ImageDraw.Draw(comp)
  21.  
  22.  
  23. i = 0
  24. while i < height:
  25. j = 0
  26. while j < width:
  27.  
  28. count = j*3+i*width
  29.  
  30. if(count < f_Size-2):
  31. d.point((j,i), fill=(ba[count],ba[count+1],ba[count+2],255))
  32. j+=1
  33.  
  34. i+=1
  35.  
  36.  
  37. comp.show()
  38. comp.save(input_file + 'File_To_Pic.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement