代码之家  ›  专栏  ›  技术社区  ›  user2667066

以编程方式获取unicode表情符号的PNG

  •  0
  • user2667066  · 技术社区  · 6 年前

    在python中,我有这样一个组合表情符号: "👨" + "\u200D" + "🔧" https://emojipedia.org/male-mechanic/ . 我想得到一个PNG版本用作打印点(在matplotlib中,如果有帮助的话)。是否有任何官方或非官方的地方可以将unicode版本的表情符号转换为PNG等价物?

    1 回复  |  直到 6 年前
        1
  •  3
  •   user2667066    6 年前

    对于其他正在寻找答案的人,目前我正在使用来自的PNG https://unicode.org/emoji/charts/full-emoji-list.html ,使用解析网页的黑客,如下所示

    class EmojiConverter:
        def __init__(self):
            import requests
            import re
            self.data = requests.get('https://unicode.org/emoji/charts/full-emoji-list.html').text
        def to_base64_png(self, emoji, version=0):
            """For different versions, you can set version = 0 for , """
            html_search_string = r"<img alt='{}' class='imga' src='data:image/png;base64,([^']+)'>" #'
            matchlist = re.findall(html_search_string.format(emoji), self.data)
            return matchlist[version]
    
    e = EmojiConverter()
    b64 = e.to_base64_png("👨"+"\u200D" + "🔧")