最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nodejs create a PNG image with text inside - Stack Overflow

programmeradmin1浏览0评论

I'm trying to create a new PNG file to serve back to clients via HTTP (as a response type image/png)

The new file is created by concatenating 3 base PNG files and adding a custom text in the middle of the image.

Problem is, there no built-in library in nodejs to do this. I spent a couple of hours searching and to my surprise, there is no pure JS library to do this. The closest thing is node-pngjs but it lacks the ability to add text. I understand that the text part is plicated since it's somewhat dependent on the OS (fonts installed, DLLs to interface with said fonts, etc).

There are other node modules that are wrappers around imageMagick (gm) and GTK (canvas) but unfortunately imageMagick is 155MB of binaries, and to use canvas you need to pile from source, install python and VS 2010 C++ Express Edition and it does not work on the lastest version of GTK.

The best I got right now is to write an .NET assembly and use it from inside node via edge.js, but that will require both Windows OS and .NET framework on the server.

Again, the plicated part here is adding the text inside the image.

Any suggestion on how to get this working without a sh**load of external dependencies?

I'm trying to create a new PNG file to serve back to clients via HTTP (as a response type image/png)

The new file is created by concatenating 3 base PNG files and adding a custom text in the middle of the image.

Problem is, there no built-in library in nodejs to do this. I spent a couple of hours searching and to my surprise, there is no pure JS library to do this. The closest thing is node-pngjs but it lacks the ability to add text. I understand that the text part is plicated since it's somewhat dependent on the OS (fonts installed, DLLs to interface with said fonts, etc).

There are other node modules that are wrappers around imageMagick (gm) and GTK (canvas) but unfortunately imageMagick is 155MB of binaries, and to use canvas you need to pile from source, install python and VS 2010 C++ Express Edition and it does not work on the lastest version of GTK.

The best I got right now is to write an .NET assembly and use it from inside node via edge.js, but that will require both Windows OS and .NET framework on the server.

Again, the plicated part here is adding the text inside the image.

Any suggestion on how to get this working without a sh**load of external dependencies?

Share Improve this question asked Mar 24, 2014 at 13:55 NickNick 72710 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Yes you are correct, the Node.js support for image processing libraries is weak, most are the wrappers of some CLI application.

The solution that I would use involves PhantomJS which has the canvas and svg support, you could use these features. It's lighter than the other options and does not require external applications to be installed. http://phantomjs/quick-start.html

发布评论

评论列表(0)

  1. 暂无评论