bonjours, je n'arrive pas à récupérer des images en format png et a les enregistrer en format jpg.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
from os import path
 
 
 
 
 
import PIL
from PIL import Image, ImageTk
import pickle
 
 
 
 
#--------------------------------------------------------------------
    #reglage
#--------------------------------------------------------------------
from PIL.ImageTk import PhotoImage
 
couleur = (48, 47, 47)
couleurmes = (113, 113, 113)
 
 
 
 
 
#--------------------------------------------------------------------
    #creation de la class
#--------------------------------------------------------------------
class Appli():
    photo: PhotoImage
 
    def __init__(self):
        self.fenetre = Tk()
        self.fenetre.geometry("1020x500")
        self.fenetre.title('Appli')
        self.fenetre.configure(background="gray11")
        self.fenetre.configure(highlightbackground="red")
        self.fenetre.configure(borderwidth="10")
        self.fenetre.configure(relief="ridge")
        self.fenetre.attributes('-alpha', 0.98)
        self.objet()
 
 
 
 
 
    #methode pour objets
    def objet(self):
 
 
 
 
        self.listeF = ['NOM :', 'PRENOM :', 'ADRESSE :', 'N° TELE :', 'MAIL :' ]
 
 
 
        R_span = 2
        R_pady = 60
        chemin_fichier = 'kard.png'  # Fichier dans le dossier de ce script
 
 
 
 
        #creation graphique
 
        for x in self.listeF:
 
            x = Label(self.fenetre, text=x, bg='gray11', fg='azure')
            x.grid(row=1, column=2, rowspan =  R_span, padx=30,pady = R_pady, sticky = NW)
            x = Entry(self.fenetre, bg='azure', fg='gray11')
            x.grid(row=1, column=3, rowspan=R_span ,padx=30, pady= R_pady, sticky = N)
 
            #recuperation de la list
 
 
            R_span += 1
            R_pady +=50
 
 
        # Label Message
 
        self.lab_mes = Label(self.fenetre, text='MESSAGE : ', bg='gray11', fg='azure')
        self.lab_mes.grid(row=1, column=4, padx=60, rowspan = 2, pady=60, sticky = N)
 
        # --------------------------------------------------------------------
        # Message
        # --------------------------------------------------------------------
        self.MES = Entry(self.fenetre, bg='azure', fg='gray11')
        self.MES.grid(row=2, column=4, padx=20, rowspan=1, ipady=55,ipadx=70, pady=0, sticky=N)
 
        # Bouton
        self.bouton = Button(self.fenetre, text='Valider',fg="azure", command=self.Entree_Get ,
                    activeforeground = 'gray11',highlightbackground="gray11", width= 10, height=2,bd =5)
        self.bouton.grid(row=2, column=4,rowspan = 3)
 
        # --------------------------------------------------------------------
        # Bouton import image
        # --------------------------------------------------------------------
        self.bouton2 = Button(self.fenetre, text='ImportImg',fg="azure", command=self.impImage ,
                    activeforeground = 'gray11',highlightbackground="gray11", width= 10, height=2,bd =5)
        self.bouton2.grid(row=2, rowspan = 9, column=1)
 
        # --------------------------------------------------------------------
        # creation canvas
        # --------------------------------------------------------------------
        self.canphoto = Canvas(self.fenetre, width=130, height=170)
        self.canphoto.grid(row=1, column=1, rowspan=2, padx=20, pady=60, sticky=W)
 
 
        # --------------------------------------------------------------------
        # creation image photo
        # --------------------------------------------------------------------
 
    def impImage(self):
 
 
        self.filename = filedialog.askopenfilename(title="Ouvrir*une*image",
                                              filetypes=[('gif*files', '.gif'),('png*files', '.png'), ('jpg*files', '.jpg')])
 
        self.image = PIL.Image.open(self.filename)
        self.photo = PIL.ImageTk.PhotoImage(self.image)
 
 
        if self.photo.height() <= 290 and self.photo.width() <= 220:
            self.canphoto.create_image(71, 92, image=self.photo, anchor=CENTER)
 
 
        else :
            messagebox.showerror("taille trop grande", 'votre photo est trop grande, vous ne devez choisire une photo entre(170px, 130px)')
 
 
 
 
 
    #--------------------------------------------------------------------
                        #creation fishier data
    #--------------------------------------------------------------------
 
    def savetexte(self, n):
 
        # enregistrement des données dans un fichier
 
        self.dir = path.dirname(__file__)
        self.dossier = path.join(self.dir, 'data_img')
        fichier = open('data_img/data.txt', 'wb')
        pickle.dump(n, fichier)  # sérialisation
        fichier.close()
 
    #def recuptext(self):  # récupération des données
     #   fichier = open('data.txt', 'rb')
      #  M = pickle.load(fichier)  # désérialisation
       # fichier.close()
 
    # --------------------------------------------------------------------
    #methode du boutton valid
    # --------------------------------------------------------------------
 
    def Entree_Get(self):
 
 
        self.list_general = []
 
 
 
 
        list_Info = []
        self.list_general.append(list_Info)
        for widget in self.fenetre.winfo_children():
            if widget.winfo_class() == 'Entry':
                list_Info.append(widget.get())
 
        self.image.save(("data_img/" + list_Info[0] + ".jpg"))
 
 
 
        self.savetexte(self.list_general)
 
 
 
 
 
#variable lié à l'application
application = Appli()
application.fenetre.mainloop()