Emoji to PNG or JPG to Node.js - how?

For the project I'm working on, I need to create an image file from emoji (ideally Apple emoji). I thought this should be pretty simple, but with every tool I use, I end up stumbling into a wall.

I also considered working with a set of emoji, for example this one , which I could request if necessary. Unfortunately, the one I'm connected to does not have Unicode 9.0 emoji, such as avocado (🥑) shrimp (🦐) or harambe (🦍). Do you know about such an updated set?

In the code, I tried opentype.js, but it does not support .ttc fonts, which is an extension of the emoji font on my mac (Apple Color Emoji.ttc). I converted the font to .ttf, but that didn't work either:

  var opentype = require('opentype.js');
  opentype.load('./build_scripts/apple_color_emoji.ttf', function (err, font) {
      if (err) {
          alert('Could not load font: ' + err);
      } else {
          console.log("loaded the font",font);

          var Canvas = require('canvas')
            , Image = Canvas.Image
            , canvas = new Canvas(200, 200)
            , ctx = canvas.getContext('2d');
          var path = font.getPath('🐐🦃', 0, 150, 72);
          path.draw(ctx);
          console.log('<img src="' + canvas.toDataURL() + '" />');
      }
  });

The result is as follows:

The result is as follows:

fontkit, , , .ttc , , Apple Color Emoji.

  var fontkit = require('fontkit');
  var font = fontkit.openSync('./build_scripts/Apple Color Emoji.ttc'); 
  // TypeError: font.layout is not a function

.ttf, svg:

  var fontkit = require('fontkit');
  var font = fontkit.openSync('./build_scripts/apple_color_emoji.ttf');
  var run = font.layout('🐐🦃');
  var svg = run.glyphs[0].path.toSVG();

  console.log(svg);
  // M-1 0ZM799 800Z

: ? emoji, .png , , , .

EDIT:

emoji ( rodrigopolo). :

var emoji = "😊".codePointAt(0).toString(16); //1f60a
var emojiFile = fs.readFileSync('./my-emoji-folder/' + emoji + '.png');

, , - !

:

, emoji Unicode 8.0, Unicode 9.0. gemoji, . ruby ​​( ), :

git clone https://github.com/github/gemoji.git
cd gemoji
bundle install
bundle exec gemoji extract some-directory/emoji

Unicode 9.0 emoji /emoji!

+6
1

fontkit, . , TTF, "Apple Color Emoji.ttc", .

const fs = require('fs');
const fontkit = require('fontkit');
const emoji = require('node-emoji');
const font = fontkit.openSync('./Apple Color Emoji.ttc').fonts[0];

let emo = emoji.get('100');
let run = font.layout(emo);
let glyph = run.glyphs[0].getImageForSize(128)

fs.writeFileSync('100.png', glyph.data);
+3

Source: https://habr.com/ru/post/1016795/


All Articles