Ce projet essai, en partant d'une IMAGESOURCE de : - appliquer des effets à l'image - la redimmensionner - changer son mode de couleur - la HAACHEER...
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.

0_hac.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/python
  2. # coding: utf-8
  3. import sys
  4. import Image
  5. import random
  6. import os
  7. import ImageDraw
  8. import ImageFont
  9. import ImageFilter
  10. import time
  11. import ImageEnhance
  12. import pickle
  13. # MILLISECONDES
  14. from datetime import datetime
  15. dt = datetime.now()
  16. dt.microsecond
  17. heure = str(dt.hour)+"h"+str(dt.minute)+"m"+str(dt.second)+"s"+str(dt.microsecond)+"ms"
  18. print dt
  19. # AGRANDISSEMENT
  20. allongement = 3
  21. # IMAGES
  22. im1 = Image.open(str(sys.argv[1])).convert('RGBA')
  23. im2 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  24. im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  25. im4 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  26. im5 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  27. im6 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
  28. im7 = Image.new("RGBA",(im1.size[0], im1.size[1]), "white") # masque alpha
  29. # LARGEUR HAUTEUR
  30. Larg = im1.size[0]
  31. Haut = im1.size[1]
  32. loadfile = False
  33. # EMPLACEMENT SCRIPT
  34. scriptpy = str(sys.argv[1])
  35. script = scriptpy[:-4]
  36. def randHaut():
  37. return random.randint(0, im1.size[1]/16)*16
  38. randomCoupeHauteur1 = [0, \
  39. randHaut(),randHaut(),randHaut(),randHaut(), \
  40. randHaut(),randHaut(),randHaut(),randHaut(), \
  41. randHaut(),randHaut(),randHaut(),randHaut(), \
  42. randHaut(),randHaut(),randHaut(),randHaut(), \
  43. randHaut(),randHaut(),randHaut(),randHaut(), \
  44. randHaut(),randHaut(),randHaut(),randHaut(), \
  45. im1.size[1]]
  46. print randomCoupeHauteur1
  47. # ENLEVE DOUBLONS
  48. randomCoupeHauteur = set(randomCoupeHauteur1)
  49. randomCoupeHauteur = list(randomCoupeHauteur)
  50. print randomCoupeHauteur
  51. # RANGEMENT
  52. randomCoupeHauteur.sort()
  53. print randomCoupeHauteur
  54. # HAACHEUUR
  55. def Hacheur(haut, bas) :
  56. n = 0
  57. i = 0
  58. while n<im6.size[0] :
  59. i+=1
  60. loop = 0
  61. # PROPORTIONS
  62. proportions = [\
  63. # (2,2),(2,4),(2,5),(2,8),(2,16),(2,32),\
  64. # (4,4),(4,5),(4,8),(4,16),(4,32),(4,64),\
  65. # (8,3),(8,5),(8,8),(8,16),(8,32),\
  66. (16,2),(16,3),(16,4),(16,5),(16,8),(16,16),(16,32),\
  67. (32,3),(32,5),(32,8),(32,16),(32,32),\
  68. (128,1),(128,2),(128,4),(128,8),\
  69. (256,1),(256,2),(256,4),\
  70. (512,1),(512,2)]
  71. '''
  72. (768,1),(768,2),\
  73. (1024,1),(1024,2),\
  74. (2048,1),\
  75. (3072,1)]
  76. '''
  77. # COPY POS X
  78. choix_rnd = random.randint(0, len(proportions)-1)
  79. largeur = proportions[choix_rnd][0]
  80. copyPosX = random.randint(0, (im1.size[0]-largeur))
  81. largeur = proportions[choix_rnd][0]
  82. repeat = proportions[choix_rnd][1]
  83. # PIXEL SIZE
  84. pixelSizeList = [1]
  85. #pixelSizeList = [1, 1, 1, 1, 2, 2, 4, 8, 16, 32, 64, 128, 256]
  86. #pixelSizeList = [1,5,25,125]
  87. pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
  88. pixelSize = pixelSizeList[pixelSizeIndex]
  89. # CROP
  90. hauteur = bas-haut
  91. cropfinal = [largeur,hauteur]
  92. im2 = im1.crop((copyPosX,haut,copyPosX+largeur,haut+hauteur))
  93. im3 = im2.resize((im2.size[0]/pixelSize, im2.size[1]/pixelSize), Image.NEAREST)
  94. im4 = im3.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
  95. im5 = im4.crop((0,0,cropfinal[0],cropfinal[1]))
  96. # MASQUE
  97. im7 = Image.new("1", (cropfinal[0],cropfinal[1]), "black")
  98. l = im7.size[0]
  99. h = im7.size[1]
  100. im7draw = ImageDraw.Draw(im7)
  101. n1 = 0
  102. ecart = 3
  103. tranches = h / ecart
  104. while n1 < tranches :
  105. rx = random.randint(0,l/2)
  106. im7draw.rectangle(((rx,n1*tranches),(rx+l/2,n1*tranches+tranches)),"white")
  107. n1 = n1 + 1
  108. # REPETITION MOTIF MASQUÉ
  109. while loop<repeat:
  110. px1 = n
  111. px2 = n + cropfinal[0]
  112. im6.paste(im5, (px1, haut, px2, bas), im7)
  113. n = n + l/2
  114. loop = loop + 1
  115. n = n - im7.size[0]/2
  116. for j in range(len(randomCoupeHauteur)-1):
  117. Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1])
  118. #TODO : inclure version du script + taille finale image
  119. #im6.putalpha(255)
  120. im6.save(script+"."+heure+".png",'PNG', quality=100)
  121. im6.show()