Skip to content

Commit 510e9c1

Browse files
committed
feat: grid view and new languages
- New style parameter with grid view - 3 new languages - Detection for transparent generated images
1 parent 03a21dd commit 510e9c1

File tree

5 files changed

+599
-179
lines changed

5 files changed

+599
-179
lines changed

README.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,45 @@ You can edit these triggers (flagged with a `🕹️` symbol) in the user config
5757

5858
1. `🌐 Language` : select the language you prefer. Here is the full list of supported languages :
5959

60-
| **Language** | **ISO639\-1** | **EmojiPedia** | **EmojiTerra** | **EmojiAll** |
61-
|-----------------|---------------|----------------|----------------|--------------|
62-
| 🇬🇧 English | en | 🟢 | 🟢 | 🟢 |
63-
| 🇫🇷 Français | fr | 🟢 | 🟢 | 🟢 |
64-
| 🇪🇸 Español | es | 🟢 | 🟢 | 🟢 |
65-
| 🇵🇹 Português | pt | 🟢 | 🟢 | 🟢 |
66-
| 🇮🇹 Italiano | it | 🟢 | 🟢 | 🟢 |
67-
| 🇩🇪 Deutsch | de | 🟢 | 🟢 | 🟢 |
68-
| 🇳🇱 Nederlands | nl | 🟢 | 🟢 | 🟢 |
69-
| 🇳🇴 Norsk | no | 🟢 | 🔴 | 🔴 |
70-
| 🇸🇪 Svenska | sv | 🟢 | 🟢 | 🟢 |
71-
| 🇩🇰 Dansk | da | 🟢 | 🟢 | 🟢 |
72-
| 🇮🇩 Melayu | ms | 🟢 | 🟢 | 🟢 |
73-
| 🇨🇳 中文 | zh | 🟢 | 🟢 | 🔴 |
74-
| 🇯🇵 日本語 | ja | 🟢 | 🟢 | 🟢 |
75-
| 🇰🇷 한국어 | ko | 🟢 | 🟢 | 🟢 |
76-
| 🇮🇳 हिंदी | hi | 🔴 | 🔴 | 🟢 |
77-
| 🇮🇳 मराठी | mr | 🔴 | 🔴 | 🔴 |
78-
| 🇮🇳 తెలుగు | te | 🔴 | 🔴 | 🔴 |
79-
| 🇧🇩 বাংলা | bn | 🔴 | 🔴 | 🟢 |
80-
| 🇱🇰 தமிழ் | ta | 🔴 | 🔴 | 🔴 |
60+
| **Language** | **ISO639-1** | **EmojiPedia** | **EmojiTerra** | **EmojiAll** |
61+
|--------------------|--------------|----------------|----------------|--------------|
62+
| 🇬🇧 English | en | 🟢 | 🟢 | 🟢 |
63+
| 🇫🇷 Français | fr | 🟢 | 🟢 | 🟢 |
64+
| 🇪🇸 Español | es | 🟢 | 🟢 | 🟢 |
65+
| 🇵🇹 Português | pt | 🟢 | 🟢 | 🟢 |
66+
| 🇮🇹 Italiano | it | 🟢 | 🟢 | 🟢 |
67+
| 🇩🇪 Deutsch | de | 🟢 | 🟢 | 🟢 |
68+
| 🇳🇱 Nederlands | nl | 🟢 | 🔴 | 🟢 |
69+
| 🇳🇴 Norsk | no | 🟢 | 🔴 | 🔴 |
70+
| 🇸🇪 Svenska | sv | 🟢 | 🔴 | 🟢 |
71+
| 🇩🇰 Dansk | da | 🟢 | 🔴 | 🟢 |
72+
| 🇮🇩 Melayu | ms | 🟢 | 🔴 | 🟢 |
73+
| 🇸🇦 ٱلْعَرَبِيَّة | ar | 🔴 | 🔴 | 🟢 |
74+
| 🇷🇺 Русский | ru | 🔴 | 🔴 | 🟢 |
75+
| 🇨🇳 中文 | zh | 🟢 | 🔴 | 🔴 |
76+
| 🇨🇳 繁體中文 | zh-hant | 🔴 | 🔴 | 🟢 |
77+
| 🇯🇵 日本語 | ja | 🟢 | 🔴 | 🟢 |
78+
| 🇰🇷 한국어 | ko | 🟢 | 🔴 | 🟢 |
79+
| 🇮🇳 हिंदी | hi | 🔴 | 🔴 | 🟢 |
80+
| 🇮🇳 मराठी | mr | 🔴 | 🔴 | 🔴 |
81+
| 🇮🇳 తెలుగు | te | 🔴 | 🔴 | 🔴 |
82+
| 🇧🇩 বাংলা | bn | 🔴 | 🔴 | 🔴 |
83+
| 🇱🇰 தமிழ் | ta | 🔴 | 🔴 | 🔴 |
84+
8185

8286
> All emojis aren't translated in all languages. Some languages aren't supported by emoji dictionnaries.
8387
8488
If you wish to use another language, open a GitHub issue [here](https://github.com/BenjaminOddou/alfred-emoji-wine/issues/new).
8589

8690
2. `✂️ Padding` : Add transparent margins to icons (in pixels).
8791

88-
3. `📖 Emoji Dictionary` : Select your online emoji dictionary.
92+
3. `🪩 Style` : Select between list or grid view.
93+
94+
4. `📖 Emoji Dictionary` : Select your online emoji dictionary.
8995

90-
4. `🌈 Skin Tone` : Select your preferred skin tone.
96+
5. `🌈 Skin Tone` : Select your preferred skin tone.
9197

92-
5. `🎷 Notification sound` : Personalize the sound of the workflow notification.
98+
6. `🎷 Notification sound` : Personalize the sound of the workflow notification.
9399

94100
### Search an emoji
95101

lang_dict.csv

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ Language,ISO639-1,EmojiPedia,EmojiTerra,EmojiAll
55
🇵🇹 Português,pt,🟢,🟢,🟢
66
🇮🇹 Italiano,it,🟢,🟢,🟢
77
🇩🇪 Deutsch,de,🟢,🟢,🟢
8-
🇳🇱 Nederlands,nl,🟢,🟢,🟢
8+
🇳🇱 Nederlands,nl,🟢,🔴,🟢
99
🇳🇴 Norsk,no,🟢,🔴,🔴
10-
🇸🇪 Svenska,sv,🟢,🟢,🟢
11-
🇩🇰 Dansk,da,🟢,🟢,🟢
12-
🇮🇩 Melayu,ms,🟢,🟢,🟢
13-
🇨🇳 中文,zh,🟢,🟢,🔴
14-
🇯🇵 日本語,ja,🟢,🟢,🟢
15-
🇰🇷 한국어,ko,🟢,🟢,🟢
10+
🇸🇪 Svenska,sv,🟢,🔴,🟢
11+
🇩🇰 Dansk,da,🟢,🔴,🟢
12+
🇮🇩 Melayu,ms,🟢,🔴,🟢
13+
🇸🇦 ٱلْعَرَبِيَّة,ar,🔴,🔴,🟢
14+
🇷🇺 Русский,ru,🔴,🔴,🟢
15+
🇨🇳 中文,zh,🟢,🔴,🔴
16+
🇨🇳 繁體中文,zh-hant,🔴,🔴,🟢
17+
🇯🇵 日本語,ja,🟢,🔴,🟢
18+
🇰🇷 한국어,ko,🟢,🔴,🟢
1619
🇮🇳 हिंदी,hi,🔴,🔴,🟢
1720
🇮🇳 मराठी,mr,🔴,🔴,🔴
1821
🇮🇳 తెలుగు,te,🔴,🔴,🔴
19-
🇧🇩 বাংলা,bn,🔴,🔴,🟢
22+
🇧🇩 বাংলা,bn,🔴,🔴,🔴
2023
🇱🇰 தமிழ்,ta,🔴,🔴,🔴

src/api.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_homebrew_prefix():
1414
homebrew_prefix = get_homebrew_prefix()
1515

1616
if 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

4848
check_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+
5068
def 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

6181
def 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

88108
try:
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

Comments
 (0)