Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created May 29, 2021 20:14
Show Gist options
  • Select an option

  • Save nolanlawson/44a86f176417e452948c5391623e2c89 to your computer and use it in GitHub Desktop.

Select an option

Save nolanlawson/44a86f176417e452948c5391623e2c89 to your computer and use it in GitHub Desktop.
Test canvas
<!doctype html>
<html>
<body>
<div></div>
<script>
const FONT_FAMILY = '"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Twemoji Mozilla","Noto Color Emoji","EmojiOne Color","Android Emoji",sans-serif';
const getTextFeature = (text2, color) => {
try {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 1;
const ctx = canvas.getContext("2d");
ctx.textBaseline = "top";
ctx.font = `100px ${FONT_FAMILY}`;
ctx.fillStyle = color;
ctx.scale(0.01, 0.01);
ctx.fillText(text2, 0, 0);
return ctx.getImageData(0, 0, 1, 1).data;
} catch (e) {
}
}
document.querySelector('div').textContent = 'text feature: ' + getTextFeature('😼')
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment