@@ -179,15 +179,37 @@ def __init__(self):
179179 @staticmethod
180180 def _ensure_logo_exists (png_path : Path ):
181181 ico_path = png_path .with_suffix (".ico" )
182- if png_path .exists () and ico_path .exists (): return
182+
183+ if not png_path .exists ():
184+ return # Si tu n'as pas le PNG, on ne peut rien faire
185+
183186 try :
184- img = Image .new ("RGBA" , (256 , 256 ), (255 , 255 , 255 , 0 ))
185- draw = ImageDraw .Draw (img )
186- draw .ellipse ([(10 , 10 ), (246 , 246 )], fill = (40 , 42 , 54 , 255 ))
187- png_path .parent .mkdir (parents = True , exist_ok = True )
188- img .save (png_path , format = "PNG" )
189- img .save (ico_path , format = "ICO" )
190- except Exception : pass
187+ # 1. Ouvrir ton PNG original
188+ img = Image .open (png_path ).convert ("RGBA" )
189+
190+ # 2. "Auto-crop" : On enlève tout le vide transparent autour du logo
191+ bbox = img .getbbox ()
192+ if bbox :
193+ img = img .crop (bbox )
194+
195+ # 3. Créer un canvas carré de 256x256 (Taille max Windows)
196+ size = 256
197+ new_img = Image .new ("RGBA" , (size , size ), (0 , 0 , 0 , 0 ))
198+
199+ # 4. Redimensionner ton logo pour qu'il touche presque les bords (98% de la taille)
200+ inner_size = int (size * 0.98 )
201+ img .thumbnail ((inner_size , inner_size ), Image .Resampling .LANCZOS )
202+
203+ # Centrer le logo sur le canvas
204+ offset = ((size - img .size [0 ]) // 2 , (size - img .size [1 ]) // 2 )
205+ new_img .paste (img , offset , img )
206+
207+ # 5. Sauvegarder par-dessus ton .ico avec TOUTES les tailles Windows
208+ # C'est la couche (256, 256) qui rend l'icône "grande" sur le bureau
209+ new_img .save (ico_path , format = "ICO" , sizes = [(256 , 256 ), (128 , 128 ), (64 , 64 ), (48 , 48 ), (32 , 32 ), (16 , 16 )])
210+
211+ except Exception as e :
212+ print (f"Erreur lors de l'optimisation de l'icône : { e } " )
191213
192214 def _show_main_window (self ):
193215 try : self .splash .destroy ()
0 commit comments