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
| from tkinter import *
from PIL import Image
import os
def photomaton() :
global img
global img0
imgf=Image.new('RGB',dim)
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
imgf.save("tempo.png")
imagetraitee=PhotoImage(file="tempo.png")
canvas.create_image(0, 256, anchor=NW,image=imagetraitee)
canvas.pack()
## if img!=img0 :
## photomaton()
canvas.mainloop()
# image d'origine img0 et création de la nouvelle image newimg
img0=Image.open("chalet.png")
dim=img0.size
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
# 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