2

In python I have a combined emoji like this: "👨" + "\u200D" + "🔧" which is normally represented as https://emojipedia.org/male-mechanic/. I want to get a PNG version to use as a plot point (in matplotlib, if that helps). Is there any official or unofficial place where I can convert unicode versions of emojis into PNG equivalents?

5
  • Resources and library (etc.) recommendations are off topic on Stack Overflow. But strangely enough, that very page that you point to lists various PNG versions of your emoji.
    – Jongware
    Commented Dec 11, 2018 at 9:45
  • Thanks. I'm unsure how to get those programmatically, though? Commented Dec 11, 2018 at 10:23
  • Also, sorry for the OT, if that's a problem. Commented Dec 11, 2018 at 10:24
  • Do you need to get them automatically? Surely you know which one(s) you want to use? Then right-click and save the images using your browser. Unless your use case is much more complicated than what you describe.
    – Jongware
    Commented Dec 11, 2018 at 10:25
  • I have (say) 10,000 points, and want to allocate a different randomly picked emoji from a set for each point. So yes, I guess programmatic is best (the points are individual people plotted in a large simulated family-tree) Commented Dec 11, 2018 at 10:28

1 Answer 1

4

For anyone else looking for an answer, at the moment I'm using the PNGs from https://unicode.org/emoji/charts/full-emoji-list.html, with a hack that parses the web page, like this

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" + "🔧")
3
  • Is there a way to do the opposite of this? I have one .png file for each emoji which I have scraped from FB. Is there a way to convert these .png emojis into string format?
    – PSK
    Commented Jul 20, 2021 at 12:28
  • That sounds hard in general. However, when scraping, could you save the unicode equivalent in the PNG metadata? Commented Jul 21, 2021 at 12:10
  • I'm not quite sure. They're not always PNGs I guess, for example, this. I have found an alternate way to do this but that requires me to send one extra request for every post I want to scrape. There is no metadata as far as I can see. Not in the form of the alt attribute of tags at least.
    – PSK
    Commented Jul 21, 2021 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.