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.

hac.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. from time import gmtime, strftime
  11. import time
  12. import ImageEnhance
  13. import pickle
  14. allongement = 2
  15. im1 = Image.open(str(sys.argv[1]))
  16. im2 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  17. im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  18. im4 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  19. im5 = Image.new("RGBA",(im1.size[0], im1.size[1]))
  20. im6 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
  21. Larg = im1.size[0]
  22. Haut = im1.size[1]
  23. loadfile = False
  24. def randHaut():
  25. return random.randint(0, im1.size[1]/8)*8
  26. randomCoupeHauteur = [0, \
  27. randHaut(),randHaut(),randHaut(),randHaut(), \
  28. randHaut(),randHaut(),randHaut(),randHaut(), \
  29. randHaut(),randHaut(),randHaut(),randHaut(), \
  30. randHaut(),randHaut(),randHaut(),randHaut(), \
  31. randHaut(),randHaut(),randHaut(),randHaut(), \
  32. randHaut(),randHaut(),randHaut(),randHaut(), \
  33. randHaut(),randHaut(),randHaut(),randHaut(), \
  34. randHaut(),randHaut(),randHaut(),randHaut(), \
  35. im1.size[1]]
  36. randomCoupeHauteur.sort()
  37. def Hacheur(haut, bas) :
  38. n = 0
  39. i = 0
  40. while n<im6.size[0] :
  41. i+=1
  42. loop = 0
  43. proportions = [\
  44. (2,8),(2,16),(2,32),\
  45. (4,4),(4,8),(4,16),(4,32),(4,64),\
  46. (8,8),(8,16),(8,32),\
  47. (16,2),(16,4),(16,8),(16,16),(16,32),\
  48. (32,8),(32,16),(32,32),\
  49. (64,4),(64,8),(64,16),\
  50. (128,2),(128,4),(128,8),\
  51. (256,1),(256,2),(256,4),\
  52. (512,1),(512,2),\
  53. (1024,1),(1024,2),\
  54. (2048,1)]
  55. choix_rnd = random.randint(0, len(proportions)-1)
  56. largeur = proportions[choix_rnd][0]
  57. randomCopyPosi = random.randint(0, (im1.size[0]-largeur))
  58. largeur = proportions[choix_rnd][0]
  59. repeat = proportions[choix_rnd][1]
  60. pixelSizeList = [1,1,2,4,8,16,32,64,128]
  61. pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
  62. pixelSize = pixelSizeList[pixelSizeIndex]
  63. hauteur = bas-haut
  64. cropfinal = [largeur,hauteur]
  65. if largeur % pixelSize != 0:
  66. croop = int(largeur / pixelSize)
  67. largeur = (croop + 1 ) * pixelSize
  68. if hauteur % pixelSize != 0:
  69. croop2 = int(hauteur / pixelSize)
  70. hauteur = (croop2 + 1 ) * pixelSize
  71. im2 = im1.crop((randomCopyPosi,haut,randomCopyPosi+largeur,haut+hauteur))
  72. im3 = im2.resize((im2.size[0]/pixelSize, im2.size[1]/pixelSize), Image.NEAREST)
  73. im4 = im3.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
  74. im5 = im4.crop((0,0,cropfinal[0],cropfinal[1]))
  75. while loop<repeat:
  76. px1 = n
  77. px2 = n + cropfinal[0]
  78. draw = ImageDraw.Draw(im5)
  79. draw.line((0, 0, 4, 0), fill="rgb(255,255,255)")
  80. draw.line((0, 0, 0, 4), fill="rgb(255,255,255)")
  81. im6.paste(im5, (px1, haut, px2, bas))
  82. n = n + cropfinal[0]
  83. loop = loop + 1
  84. for j in range(len(randomCoupeHauteur)-1):
  85. Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1])
  86. scriptpy = str(sys.argv[1])
  87. script = scriptpy[:-3]
  88. n = "1.1"
  89. im6.save(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".png",'PNG', quality=100)