tkrkt / text2png

text-to-png generator for Node.js
MIT License
188 stars 50 forks source link

Getting "node: symbol lookup" error when using function within express app? #26

Open skeddles opened 5 years ago

skeddles commented 5 years ago

So I'm having a really weird problem, where the script works fine when run by node, but when trying to implement it into my express app, it gets an error every time. Here is the error I'm getting:

node: symbol lookup error: /home/ubuntu/workspace/node_modules/canvas/build/Release/libpangoft2-1.0.so.0: undefined symbol: FcWeightFromOpenTypeDouble

And here is the full code of the route:

router.get('/test', function(req, res, next) {
  var text2png = require('text2png');

  var textImage = text2png('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789', {
    font: 8+'px font',
    color: 'white',
    padding: 10,
    lineSpacing: 4,
    backgroundColor: '#332f35',
    localFontPath: 'renew.ttf',
    localFontName: 'font',
  });

  fs.writeFileSync('out.png', textImage);

});

But if I copy and paste that same code into it's own file, and run it with node file.js, it works perfectly and outputs the file.

I'm on Ubuntu 16.4.0

Hope we can resolve this as the script is great when it works!

skeddles commented 5 years ago

After looking around some more, seems other people got that error which was caused by the package fontconfig, specifically the ubuntu version.

After testing my code in different positions, I've discovered it breaks whenever node-gd is included in the script before it's run.

Will continue to search for a solution.

skeddles commented 5 years ago

I get the same problem with writing any text using node-canvas, so I'll open an issue with them.