Advertisement
MoSBanapple

Untitled

Nov 24th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import sys
  2. import os.path
  3. import numpy as np
  4. import PIL
  5. from random import randint
  6. try:
  7. import Image
  8. except ImportError:
  9. from PIL import Image
  10.  
  11.  
  12. def readFile(nameoffile):
  13. list = []
  14. with open(nameoffile, 'r') as f:
  15. for line in f:
  16.  
  17. list.append(line.rstrip())
  18. return list
  19.  
  20. def randomTeam(characters):
  21. team = []
  22. while len(team) < 3:
  23. num = randint(0,len(characters)-1)
  24. chosen = characters[num]
  25. if chosen[0] == 'm':
  26. continue
  27. overlap = False
  28. for iter in team:
  29. if chosen[0] == iter[0]:
  30. overlap = True
  31. if not overlap:
  32. team.append(chosen)
  33.  
  34. while len(team) < 4:
  35. master = characters[randint(0,len(characters)-1)]
  36. if master[0] == 'm':
  37. team.append(master)
  38. print(team)
  39. return team
  40.  
  41. list = readFile('characters.txt')
  42. list_im = randomTeam(list)
  43. '''
  44. while ('b ed.jpg' not in list_im):
  45. list_im = randomTeam(list)
  46. '''
  47. imgs = [ PIL.Image.open(i) for i in list_im ]
  48. # pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here)
  49. min_shape = sorted( [(np.sum(i.size), i.size ) for i in imgs])[0][1]
  50. imgs_comb = np.hstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) )
  51.  
  52. # save that beautiful picture
  53. imgs_comb = PIL.Image.fromarray( imgs_comb)
  54. imgs_comb.save( 'Trifecta.jpg' )
  55.  
  56. # for a vertical stacking it is simple: use vstack
  57.  
  58. """
  59. imgs_comb = np.vstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) )
  60. imgs_comb = PIL.Image.fromarray( imgs_comb)
  61. imgs_comb.save( 'Trifecta_vertical.jpg' )
  62. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement