@@ -16,26 +16,26 @@ def load(self, image_path, width=50, height=50, normalize_color=True):
1616
1717 if platform .system () == 'Darwin' :
1818 return None
19- #
20- # from PIL import Image
21- # from PIL import ImageTk
22- # background_color = ImageUtility.hex_to_rgb(self.theme_manager.background_color)
23- # highlight_color = ImageUtility.hex_to_rgb(self.theme_manager.highlight_color)
24- # original = Image.open(image_path)
25- # resized = original.resize((width, height), Image.ANTIALIAS)
26- #
27- # if normalize_color:
28- # pixel_access = resized.load()
29- # for y in range(resized.size[1]):
30- # for x in range(resized.size[0]):
31- # pixel = pixel_access[x, y]
32- # if pixel[0] < 50:
33- # pixel_access[x, y] = (background_color[0] + pixel_access[x, y][0],
34- # background_color[1] + pixel_access[x, y][1],
35- # background_color[2] + pixel_access[x, y][2])
36- # elif pixel[0] > 50:
37- # pixel_access[x, y] = (int(highlight_color[0] * pixel_access[x, y][0] / 255),
38- # int(highlight_color[1] * pixel_access[x, y][1] / 255),
39- # int(highlight_color[2] * pixel_access[x, y][2] / 255))
40- #
41- # return ImageTk.PhotoImage(resized)
19+
20+ from PIL import Image
21+ from PIL import ImageTk
22+ background_color = ImageUtility .hex_to_rgb (self .theme_manager .background_color )
23+ highlight_color = ImageUtility .hex_to_rgb (self .theme_manager .highlight_color )
24+ original = Image .open (image_path )
25+ resized = original .resize ((width , height ), Image .ANTIALIAS )
26+
27+ if normalize_color :
28+ pixel_access = resized .load ()
29+ for y in range (resized .size [1 ]):
30+ for x in range (resized .size [0 ]):
31+ pixel = pixel_access [x , y ]
32+ if pixel [0 ] < 50 :
33+ pixel_access [x , y ] = (background_color [0 ] + pixel_access [x , y ][0 ],
34+ background_color [1 ] + pixel_access [x , y ][1 ],
35+ background_color [2 ] + pixel_access [x , y ][2 ])
36+ elif pixel [0 ] > 50 :
37+ pixel_access [x , y ] = (int (highlight_color [0 ] * pixel_access [x , y ][0 ] / 255 ),
38+ int (highlight_color [1 ] * pixel_access [x , y ][1 ] / 255 ),
39+ int (highlight_color [2 ] * pixel_access [x , y ][2 ] / 255 ))
40+
41+ return ImageTk .PhotoImage (resized )
0 commit comments