Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a user's computer supports Emoji?

This question could be generalized to any character, I suppose; but my specific use-case are emoji.

I'm writing a command-line program, and I want to detect if the computer on which it is running has a font installed that can display emoji; and whether the current terminal application will display them in that font.

At the moment, I have a hack in place that simply filters them out on non-OS X; but I don't want to short-change Linux users who have an emoji-enabled setup. I'd prefer to do this the โ€˜right way.โ€™

Thanks! ๐Ÿ’–

like image 418
ELLIOTTCABLE Avatar asked May 08 '14 17:05

ELLIOTTCABLE


1 Answers

Your script would have to:

  1. know which system fonts are available, and where the font files are (for example C:\Windows\Fonts)
  2. inspect these files for their content. I suppose inspecting them could be done in a technical way, unravelling file formats. But you could also simulate the visual use, by calculating the bounding box or simulate font usage for the Emoji characters.

If you're into PHP, you could calculate the bounding box of the TTF fonts that are known for the Emoji, and see if the value is what is to be expected of a font that supports it.

You could also simulate the font use by drawing in a black in-memory image with a white colored font using GD, and calculate the (average) amount of white pixels to see if it fits an expected threshold.

You also asked for a check if the current terminal application will display them. For that you need to be able to check the config, which is non trivial since you'd need to be able to differentiate on all terminal applications. A practical solution would be to display some Emoji with the current font and just ask the user if it is visable. After all, you need to rely on the user anyway if the terminal application needs to support Emoji?

like image 132
Code4R7 Avatar answered Nov 02 '22 23:11

Code4R7