1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| from tkinter import *
from PIL import Image
import os
def photomaton() :
global img
global n
imgf=Image.new('RGB',dim)
if img!=img0 or n==0 : #les 2 images sont du même type donc je peux les comparer
for i in range(dim[0]):
for j in range(dim[1]):
if i%2==0 and j%2==0:
imgf.putpixel((i//2,j//2),img.getpixel((i,j)))
if i%2==1 and j%2==0:
imgf.putpixel((i//2+dim[0]//2,j//2),img.getpixel((i,j)))
if i%2==0 and j%2==1:
imgf.putpixel((i//2,j//2+dim[1]//2),img.getpixel((i,j)))
else :
imgf.putpixel((i//2+dim[0]//2,j//2+dim[1]//2),img.getpixel((i,j)))
img=imgf
n=n+1
else :
n=0
photomaton()
imgf.save("tempo.png")
imagetraitee=PhotoImage(file="tempo.png")
canvas.create_image(0, 256, anchor=NW,image=imagetraitee)
canvas.pack()
canvas.mainloop()
# image d'origine img0 et création de la nouvelle image newimg
imgOrigine=Image.open("chalet.png")
dim=imgOrigine.size
img0=Image.new('RGB',dim) #Astuce lourdingue pour modifier le type de l'image PngImageFile en Image
for m in range (dim[0]) :
for n in range(dim[1]) :
img0.putpixel((m,n),imgOrigine.getpixel((m,n)))
newimg=Image.new('RGB',dim)
newimg.save("tempo.png") #image tempo créée "pour rien" pour éviter erreur car tempo inexistant si Quitter directement
img=img0
n=0
# fenetre et boutons
fenetre = Tk()
imgTK0= PhotoImage(file="chalet.png")
canvas = Canvas(fenetre,width=600, height=500)
canvas.create_image(0, 0, anchor=NW,image=imgTK0)
canvas.pack()
titre = Label(fenetre, text="Traitement d'image minimaliste ....",foreground="red",background="yellow")
titre.pack()
bou1 = Button(fenetre,text='Quitter',command=fenetre.destroy) #Bouton Quitter
bou1.place(relx=1, rely=1, anchor=SE)
bou5 = Button(fenetre,text='Photomaton',command=photomaton) #Bouton "photomaton"
bou5.place(relx=0.8, rely=0.5, anchor="c")
fenetre.mainloop()
os.remove("tempo.png") #suppression fichier temporaire |
Partager