@@ -14,7 +14,7 @@ def get_homebrew_prefix():
1414homebrew_prefix = get_homebrew_prefix ()
1515
1616if homebrew_prefix :
17- python_version = f" { sys .version_info .major } .{ sys .version_info .minor } "
17+ python_version = f' { sys .version_info .major } .{ sys .version_info .minor } '
1818 pillow_dir = f'{ homebrew_prefix } /Cellar/pillow'
1919 try :
2020 latest_version = max (os .listdir (pillow_dir ))
@@ -47,16 +47,36 @@ def get_homebrew_prefix():
4747
4848check_e_type = ['flag:' , 'keycap:' ]
4949
50+ def is_blank_image (image ):
51+ """Efficiently checks if an image is blank (fully transparent or one solid color)."""
52+ pixels = image .getdata ()
53+ first_pixel = next (iter (pixels )) # Get the first pixel without loading all into memory
54+
55+ all_same = True
56+ all_transparent = True
57+
58+ for pixel in pixels :
59+ if pixel != first_pixel :
60+ all_same = False
61+ if pixel [3 ] != 0 : # Check transparency (alpha channel)
62+ all_transparent = False
63+ if not all_same and not all_transparent :
64+ return False # Exit early if image is neither blank nor fully transparent
65+
66+ return all_same or all_transparent # Returns True if either condition is met
67+
5068def convert_emoji_to_png (emoji , name ):
5169 image_size = (64 + padding , 64 + padding ) # set image size
52- image = Image .new (" RGBA" , image_size , (0 , 0 , 0 , 0 )) # Set transparent background
70+ image = Image .new (' RGBA' , image_size , (0 , 0 , 0 , 0 )) # Set transparent background
5371 font_size = 64 # Adjusted font size
54- font_path = " /System/Library/Fonts/Apple Color Emoji.ttc"
72+ font_path = ' /System/Library/Fonts/Apple Color Emoji.ttc'
5573 font = ImageFont .truetype (font_path , font_size , encoding = 'unic' )
5674 draw_position = (int ((image_size [0 ] - font_size ) / 2 ), int ((image_size [1 ] - font_size ) / 2 ))
5775 draw = ImageDraw .Draw (image )
5876 draw .text (draw_position , emoji , font = font , embedded_color = True )
59- image .save (f"{ icons_folder_path } /{ name .replace (':' , '' )} .png" , "PNG" )
77+ if is_blank_image (image ):
78+ raise ValueError (f"Generated image for '{ emoji } ' is blank or unsupported." )
79+ image .save (f'{ icons_folder_path } /{ name .replace (':' , '' )} .png' , 'PNG' )
6080
6181def remove_skin_tones (emoji ):
6282 skin_tone_range = range (0x1F3FB , 0x1F3FF + 1 )
@@ -69,11 +89,11 @@ def get_skin_tones(emoji):
6989 skin_tones .append ('none' )
7090 else :
7191 skin_tone_dict = {
72- 0x1F3FB : " light skin tone" ,
73- 0x1F3FC : " medium-light skin tone" ,
74- 0x1F3FD : " medium skin tone" ,
75- 0x1F3FE : " medium-dark skin tone" ,
76- 0x1F3FF : " dark skin tone"
92+ 0x1F3FB : ' light skin tone' ,
93+ 0x1F3FC : ' medium-light skin tone' ,
94+ 0x1F3FD : ' medium skin tone' ,
95+ 0x1F3FE : ' medium-dark skin tone' ,
96+ 0x1F3FF : ' dark skin tone'
7797 }
7898 for char in emoji :
7999 value_skin_tone = skin_tone_dict .get (ord (char ))
@@ -83,15 +103,15 @@ def get_skin_tones(emoji):
83103 skin_tones .append ('base' )
84104 return list (set (skin_tones ))
85105
86- skin_tones = [" light skin tone" , " medium-light skin tone" , " medium skin tone" , " medium-dark skin tone" , " dark skin tone" ]
106+ skin_tones = [' light skin tone' , ' medium-light skin tone' , ' medium skin tone' , ' medium-dark skin tone' , ' dark skin tone' ]
87107
88108try :
89109 api_url = 'https://unicode.org/Public/emoji/latest/emoji-test.txt'
90110 api_response = request .urlopen (api_url ).read ().decode ('utf-8' )
91111 lines = [line .strip () for line in api_response .split ('\n ' ) if ('; fully-qualified' in line ) or ('; component' in line )]
92112
93- lang_url_1 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotations/{ language } .xml'
94- lang_url_2 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotationsDerived/{ language } .xml'
113+ lang_url_1 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotations/{ language . replace ( "-" , "_" ) } .xml'
114+ lang_url_2 = f'https://raw.githubusercontent.com/unicode-org/cldr/main/common/annotationsDerived/{ language . replace ( "-" , "_" ) } .xml'
95115 lang_response_1 = request .urlopen (lang_url_1 ).read ().decode ('utf-8' )
96116 lang_response_2 = request .urlopen (lang_url_2 ).read ().decode ('utf-8' )
97117
@@ -105,7 +125,7 @@ def get_skin_tones(emoji):
105125 for line in lines :
106126 array = re .split (r'\bfully-qualified\b|\bcomponent\b' , line )[1 ].strip ().split (' ' , 3 )
107127 emoji , name = array [1 ], array [- 1 ]
108- full_emojis .append ({" emoji" : emoji , " name" : name })
128+ full_emojis .append ({' emoji' : emoji , ' name' : name })
109129 clean_emoji = remove_skin_tones (emoji )
110130 if emoji != clean_emoji :
111131 cleaned_emojis .append (clean_emoji )
@@ -143,10 +163,10 @@ def get_skin_tones(emoji):
143163 })
144164
145165 for item in langs :
146- if item [" value" ] == language :
147- lang = item [" title" ]
166+ if item [' value' ] == language :
167+ lang = item [' title' ]
148168 break
149- info = {'time' : datetime .datetime .now ().strftime (" %d-%m-%Y %H:%M:%S" ), 'lang' : {'title' : lang , 'value' : language }, 'workflow_version' : workflow_version }
169+ info = {'time' : datetime .datetime .now ().strftime (' %d-%m-%Y %H:%M:%S' ), 'lang' : {'title' : lang , 'value' : language }, 'workflow_version' : workflow_version }
150170 with open (api_file_path , 'w' , encoding = 'utf-8' ) as file :
151171 json .dump ({'info' : info , 'items' : items }, file , ensure_ascii = False , indent = 4 )
152172
@@ -156,7 +176,7 @@ def get_skin_tones(emoji):
156176 image_path = os .path .join (assets_folder_path , i )
157177 image = Image .open (image_path )
158178 width , height = image .size
159- new_image = Image .new (" RGBA" , (width + padding , height + padding ), (0 , 0 , 0 , 0 ))
179+ new_image = Image .new (' RGBA' , (width + padding , height + padding ), (0 , 0 , 0 , 0 ))
160180 new_image .paste (image , (int (padding / 2 ), int (padding / 2 )))
161181 output_path = os .path .join (icons_folder_path , i )
162182 new_image .save (output_path )
0 commit comments