pixelisation v3 : hac.py
This commit is contained in:
parent
8045d3c2ba
commit
a54321559d
16
geany_run_script.sh
Normal file
16
geany_run_script.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm $0
|
||||
|
||||
python "hac.py"
|
||||
|
||||
echo "
|
||||
|
||||
------------------
|
||||
(program exited with code: $?)"
|
||||
|
||||
|
||||
echo "Press return to continue"
|
||||
#to be more compatible with shells like dash
|
||||
dummy_var=""
|
||||
read dummy_var
|
111
hac.py
Normal file
111
hac.py
Normal file
@ -0,0 +1,111 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
|
||||
import sys
|
||||
import Image
|
||||
import random
|
||||
import os
|
||||
import ImageDraw
|
||||
import ImageFont
|
||||
import ImageFilter
|
||||
from time import gmtime, strftime
|
||||
import time
|
||||
import ImageEnhance
|
||||
import pickle
|
||||
|
||||
allongement = 2
|
||||
im1 = Image.open(str(sys.argv[1]))
|
||||
im2 = Image.new("RGBA",(im1.size[0], im1.size[1]))
|
||||
im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
|
||||
im4 = Image.new("RGBA",(im1.size[0], im1.size[1]))
|
||||
im5 = Image.new("RGBA",(im1.size[0], im1.size[1]))
|
||||
im6 = Image.new("RGBA",(im1.size[0]*allongement, im1.size[1]))
|
||||
|
||||
Larg = im1.size[0]
|
||||
Haut = im1.size[1]
|
||||
loadfile = False
|
||||
|
||||
def randHaut():
|
||||
return random.randint(0, im1.size[1]/8)*8
|
||||
|
||||
|
||||
randomCoupeHauteur = [0, \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
randHaut(),randHaut(),randHaut(),randHaut(), \
|
||||
im1.size[1]]
|
||||
randomCoupeHauteur.sort()
|
||||
|
||||
|
||||
def Hacheur(haut, bas) :
|
||||
n = 0
|
||||
i = 0
|
||||
while n<im6.size[0] :
|
||||
i+=1
|
||||
loop = 0
|
||||
|
||||
proportions = [\
|
||||
(2,8),(2,16),(2,32),\
|
||||
(4,4),(4,8),(4,16),(4,32),(4,64),\
|
||||
(8,8),(8,16),(8,32),\
|
||||
(16,2),(16,4),(16,8),(16,16),(16,32),\
|
||||
(32,8),(32,16),(32,32),\
|
||||
(64,4),(64,8),(64,16),\
|
||||
(128,2),(128,4),(128,8),\
|
||||
(256,1),(256,2),(256,4),\
|
||||
(512,1),(512,2),\
|
||||
(1024,1),(1024,2),\
|
||||
(2048,1)]
|
||||
|
||||
choix_rnd = random.randint(0, len(proportions)-1)
|
||||
largeur = proportions[choix_rnd][0]
|
||||
randomCopyPosi = random.randint(0, (im1.size[0]-largeur))
|
||||
largeur = proportions[choix_rnd][0]
|
||||
repeat = proportions[choix_rnd][1]
|
||||
|
||||
pixelSizeList = [1,1,2,4,8,16,32,64,128]
|
||||
pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
|
||||
pixelSize = pixelSizeList[pixelSizeIndex]
|
||||
|
||||
hauteur = bas-haut
|
||||
cropfinal = [largeur,hauteur]
|
||||
|
||||
if largeur % pixelSize != 0:
|
||||
croop = int(largeur / pixelSize)
|
||||
largeur = (croop + 1 ) * pixelSize
|
||||
|
||||
if hauteur % pixelSize != 0:
|
||||
croop2 = int(hauteur / pixelSize)
|
||||
hauteur = (croop2 + 1 ) * pixelSize
|
||||
|
||||
im2 = im1.crop((randomCopyPosi,haut,randomCopyPosi+largeur,haut+hauteur))
|
||||
im3 = im2.resize((im2.size[0]/pixelSize, im2.size[1]/pixelSize), Image.NEAREST)
|
||||
im4 = im3.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
|
||||
im5 = im4.crop((0,0,cropfinal[0],cropfinal[1]))
|
||||
|
||||
while loop<repeat:
|
||||
px1 = n
|
||||
px2 = n + cropfinal[0]
|
||||
|
||||
draw = ImageDraw.Draw(im5)
|
||||
draw.line((0, 0, 4, 0), fill="rgb(255,255,255)")
|
||||
draw.line((0, 0, 0, 4), fill="rgb(255,255,255)")
|
||||
|
||||
im6.paste(im5, (px1, haut, px2, bas))
|
||||
|
||||
n = n + cropfinal[0]
|
||||
loop = loop + 1
|
||||
|
||||
|
||||
for j in range(len(randomCoupeHauteur)-1):
|
||||
Hacheur(randomCoupeHauteur[j], randomCoupeHauteur[j+1])
|
||||
|
||||
scriptpy = str(sys.argv[1])
|
||||
script = scriptpy[:-3]
|
||||
n = "1.1"
|
||||
im6.save(script+"."+n+"_"+strftime("%Y%m%d-%Hh%Mm%Ss", gmtime())+".png",'PNG', quality=100)
|
107
hacheur.py
107
hacheur.py
@ -27,7 +27,7 @@ multiples 768 : 768 1536 2304 3072 3840 4608 5376 6144 6912 7680 8448 9216 9984
|
||||
|
||||
|
||||
#rapport d'allongement de la nouvelle image par rapport à la largeur de l'image originale
|
||||
allongement = 2
|
||||
allongement = 1
|
||||
|
||||
#ouvertrure de l'image source et conversion en mode couleur 1bit
|
||||
#im1 = Image.open(str(sys.argv[1])).convert('1')
|
||||
@ -79,7 +79,7 @@ for i in range(1):
|
||||
# genre comme si qu'on avait un 16 pistes :)
|
||||
# nombre aleatoire compris dans les limites de l'image
|
||||
def randHaut():
|
||||
return random.randint(0, im1.size[1]/32)*32
|
||||
return random.randint(0, im1.size[1]/8)*8
|
||||
|
||||
if loadfile:
|
||||
randomCoupeHauteur = seq.randomCoupeHauteur
|
||||
@ -112,35 +112,25 @@ def Hacheur(haut, bas) :
|
||||
choix_rnd = seq.choix[i]
|
||||
randomCopyPosi = seq.randomCopyPosi[i]
|
||||
else:
|
||||
'''
|
||||
8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128 136 144 152 160 168
|
||||
'''
|
||||
#proportions = [(160,6),(120,4),(120,8),(80,16),(60,16),(20,32),(8,24),(8,16),(5,64),(3,24),(2,24),(1,256),(1,128),(1,64),(1,32),(1,16),(1,8)]
|
||||
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(24,32),(24,16),(16,32),(16,16),(16,8),(16,2),(16,1),(8,24),(8,16),(8,8),(8,4),(8,2),(8,1)]
|
||||
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
|
||||
#proportions = [(2560,1),(1280,2),(1280,1),(640,2),(640,1),(320,4),(320,2),(160,6),(160,2),(120,4),(120,8),(120,1),(80,16),(80,4),(64,16),(64,8),(64,1),(32,1),(32,2),(32,4),(32,8),(32,32),(16,1),(16,2),(16,4),(16,16),(16,32)]
|
||||
proportions = [ (16,2),(16,4),(16,8),(16,16),(16,32),\
|
||||
(32,8),(32,16),(32,32),\
|
||||
(64,4),(64,8),(64,16),\
|
||||
(128,2),(128,4),(128,8),\
|
||||
(256,1),(256,2),(256,4),\
|
||||
(512,1),(512,2),\
|
||||
(1024,1),(1024,2),\
|
||||
(2048,1)]
|
||||
|
||||
|
||||
'''
|
||||
proportions = [ (768,2),\
|
||||
(512,4),\
|
||||
(256,8),\
|
||||
(128,4),(128,16),\
|
||||
(64,4),(64,8),(64,16),\
|
||||
(32,8),(32,16),(32,32),(32,32),(32,64),(32,128),\
|
||||
(16,1),(16,4),(16,16),(16,64)]
|
||||
'''
|
||||
|
||||
'''
|
||||
1,2,4,8,16,32,64,128,256,512,1024
|
||||
|
||||
|
||||
|
||||
|
||||
proportions = [\
|
||||
(2,8),(2,16),(2,32),\
|
||||
(4,4),(4,8),(4,16),(4,32),(4,64),\
|
||||
(8,8),(8,16),(8,32),\
|
||||
(16,2),(16,4),(16,8),(16,16),(16,32),\
|
||||
(32,8),(32,16),(32,32),\
|
||||
(64,4),(64,8),(64,16)]
|
||||
'''
|
||||
(128,2),(128,4),(128,8),\
|
||||
(256,1),(256,2),(256,4),\
|
||||
(512,1),(512,2),\
|
||||
(1024,1),(1024,2),\
|
||||
(2048,1)]
|
||||
'''
|
||||
|
||||
seq.proportions = proportions
|
||||
@ -152,7 +142,7 @@ def Hacheur(haut, bas) :
|
||||
largeur = proportions[choix_rnd][0]
|
||||
|
||||
# positionnement de la copie, aleatoirement, entre 0 et la largeur totale de l'image
|
||||
randomCopyPosi = random.randint(0, (im1.size[0]-largeur))
|
||||
randomCopyPosi = random.randint(0, (im1.size[0]-largeur-32))
|
||||
#randomCopyPosi = seq.randomCopyPosi
|
||||
seq.randomCopyPosi.append(randomCopyPosi)
|
||||
|
||||
@ -172,12 +162,12 @@ def Hacheur(haut, bas) :
|
||||
cx2 = randomCopyPosi + largeur
|
||||
#print "im3 = im2.crop : "+str(im3.size)
|
||||
|
||||
draw = ImageDraw.Draw(im4)
|
||||
#draw = ImageDraw.Draw(im4)
|
||||
|
||||
loop = 0
|
||||
|
||||
#pixelSizeList = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,4,4,8]
|
||||
pixelSizeList = [1,1,1,1,1,1,1,1,1,1,2,2,4,8,16]
|
||||
pixelSizeList = [1,8,16,32]
|
||||
pixelSizeIndex = random.randint(0,len(pixelSizeList)-1)
|
||||
pixelSize = pixelSizeList[pixelSizeIndex]
|
||||
|
||||
@ -194,34 +184,49 @@ def Hacheur(haut, bas) :
|
||||
bas droit (largeur-1, hauteur-1)
|
||||
'''
|
||||
|
||||
print
|
||||
print "-------------------------------------------"
|
||||
print "largeur="+str(largeur)
|
||||
print "hauteur="+str(hauteur)
|
||||
print pixelSize
|
||||
|
||||
if largeur % pixelSize != 0:
|
||||
croop = largeur / pixelSize
|
||||
largeur = (int(croop) + 1 ) * pixelSize
|
||||
croop = int(largeur / pixelSize)
|
||||
largeur = (croop + 1 ) * pixelSize
|
||||
print "croop="+str(croop)
|
||||
print "pixelSize="+str(pixelSize)
|
||||
print "largeur="+str(largeur)
|
||||
|
||||
if hauteur % pixelSize != 0:
|
||||
croop2 = hauteur / pixelSize
|
||||
hauteur = (int(croop2) + 1 ) * pixelSize
|
||||
croop2 = int(hauteur / pixelSize)
|
||||
hauteur = (croop2 + 1 ) * pixelSize
|
||||
print "hauteur="+str(hauteur)
|
||||
|
||||
# decoupage du sample
|
||||
|
||||
# decoupage du sample :
|
||||
# sample aux dimensions de l'effet
|
||||
im5 = im2.crop((randomCopyPosi,haut,randomCopyPosi+largeur,haut+hauteur))
|
||||
im3 = im2.crop((cx1,haut,cx2,bas))
|
||||
|
||||
''' COLLAGE DU SAMPLE
|
||||
'''
|
||||
|
||||
#boutImage = im3
|
||||
#im3 = Image.new("RGBA",(im1.size[0], im1.size[1]))
|
||||
|
||||
''' PIXELISATION '''
|
||||
if pixelSize > 1 :
|
||||
im5 = im5.resize((im3.size[0]/pixelSize, im3.size[1]/pixelSize), Image.NEAREST)
|
||||
im5 = im5.resize((im3.size[0]*pixelSize, im3.size[1]*pixelSize), Image.NEAREST)
|
||||
boutImage = im5.resize((im5.size[0]/pixelSize, im5.size[1]/pixelSize), Image.NEAREST)
|
||||
boutImage = im5.resize((im5.size[0]*pixelSize, im5.size[1]*pixelSize), Image.NEAREST)
|
||||
else :
|
||||
boutImage = im5
|
||||
|
||||
im3 = im5.crop((0,0,cropfinal[0],cropfinal[1]))
|
||||
# le sample final (bonnes dimensions)
|
||||
im3 = boutImage.crop((0,0,cropfinal[0],cropfinal[1]))
|
||||
|
||||
print "im5.size="+str(im5.size)
|
||||
print "im3.size1="+str(im3.size)
|
||||
|
||||
''' COLLAGE DU SAMPLE
|
||||
'''
|
||||
|
||||
while loop<repeat:
|
||||
px1 = n
|
||||
px2 = n + largeur
|
||||
px2 = n + cropfinal[0]
|
||||
#lignes colorées de 1 pix
|
||||
#draw = ImageDraw.Draw(boutImage)
|
||||
#draw.line((0,0,0,4), fill="rgb(128,128,128)")
|
||||
@ -230,11 +235,17 @@ def Hacheur(haut, bas) :
|
||||
draw.line((0, 0, largeur-1, 0), fill="rgb(255,255,255)")
|
||||
draw.line((largeur-1, 0, largeur-1, bas-haut), fill="rgb(255,255,255)")
|
||||
|
||||
print "px2-px1="+str(px2-px1)
|
||||
print "bas-haut="+str(bas-haut)
|
||||
print "im4.size="+str(im4.size)
|
||||
print
|
||||
|
||||
im4.paste(im3, (px1, haut, px2, bas))
|
||||
|
||||
n = n + largeur
|
||||
loop = loop + 1
|
||||
|
||||
|
||||
print
|
||||
''' OPTIONS '''
|
||||
def TrancheHorizontale() :
|
||||
# tirage au hasard de la bande copiee
|
||||
|
Loading…
Reference in New Issue
Block a user