Render image of text with unicode/emoji


#1

I want to generate and serve an image of text.

At the moment I’m using text2png:

text2png('this string', {font: '14px Courier', bgColor: 'white'})

I’ve got it working for simple strings.

However, text2png doesn’t seem to be able to do unicode/emoji at least by default on glitch:

It’s turning :fire: into enter image description here and chinese characters, e.g. 中文, into enter image description here.

How can I render strings containing these kinds of characters into images?

text2png was working perfectly in other respects.

Also, locally on my MacBook it rendered the chinese characters but it still didn’t do the emoji correctly.


#2

I also confirmed same behavior, but it is hard for text2png to fix.

text2png depends on node-canvas, it depends on cairo.
Stable version of cairo(1.14.12) probably does not support emoji…

On the other hand, development version of cairo(1.15.8) supports emoji.

https://cairographics.org/news/cairo-1.15.8/

Features and Enhancements

  • Support colored emoji glyphs, stored as PNG images in OpenType fonts.

If you get and build the development version of cairo, you may be able to use emoji.
(I have not tried it yet)


#3

Anyone here know how I might be able to build development versions of Cairo on glitch to fix this problem?


#4

you might be able to apt-get install cairo (i’d check the cairo docs) but you’d have to have it installed in /app since we don’t give you to permission to write to everywhere in the container. if you get it running, you’d then have to point your node-canvas module to the locally installed cairo and not the one it installs as its own dependency