Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does GitHub detect whether the browser has color emoji support?

Tags:

html

github

emoji

When visiting GitHub using a browser without color emoji support, it loads emoji glyphs as image files.

GitHub without color emoji support

But when visiting GitHub using a browser that does have color emoji support, it lets the browser render the glyphs normally instead.

GitHub with color emoji support

How can GitHub know whether the browser supports color emoji or not?

like image 866
stommestack Avatar asked Nov 02 '16 16:11

stommestack


1 Answers

I do that like this :

var canvas = document.createElement("canvas"),
    ctx = canvas.getContext("2d");

canvas.style="height:100px;width:100px;position:absolute;top:60%;background:white";
document.body.appendChild(canvas);
ctx.fillStyle ="#FFF";
ctx.font="100px Arial";
ctx.fillText('😡',100,100);
var d = ctx.getImageData(50, 50, 1, 1).data;
if (d[0] + d[1] + d[2] === 0) {
    //need twemoji or something else
} else {
    //nothing to do   
}
like image 144
bubbatls Avatar answered Sep 27 '22 21:09

bubbatls