在Node.JS上,我应该使用哪个库进行服务器端图像操作?

时间:2022-05-26 16:51:59

I found a quite large list of available libraries on Node.JS wiki but I'm not sure which of those are more mature and provide better performance. Basically I want to do the following:

我在Node上找到了一个相当大的可用库列表。JS wiki,但我不确定哪一个更成熟,提供更好的性能。基本上我想做的是:

  1. load some images to a server from external sources
  2. 从外部源加载一些图像到服务器。
  3. put them onto one big canvas
  4. 把它们放到一个大画布上。
  5. crop and mask them a bit
  6. 修剪一下,把它们遮一下
  7. apply a filter or two
  8. 应用一两个过滤器
  9. Resize the final image and give a link to it
  10. 调整最终图像的大小并给它一个链接

Big plus if the node package works on both Linux and Windows.

如果节点包在Linux和Windows上都能运行,那就更好了。

3 个解决方案

#1


173  

Answering my own question

回答我的问题

I spent two days digging through Node.js graphics libraries.

我花了两天时间研究Node。js图形库。

node-canvas

node-canvas

  • I tried it first since I'm quite familiar with <canvas> API. It's a huge plus for a library.
  • 我首先尝试了它,因为我非常熟悉 API。这对图书馆来说是一个巨大的好处。
  • it requires Cairo which doesn't have an easy Windows download. I found it in GTK+ distribution though.
  • 它需要Cairo,它没有简单的Windows下载。我在GTK+发行版中找到了它。
  • moreover it needs native library binding code to be compiled on module installation. It uses Node-Waf which hasn't being ported to Windows yet.
  • 此外,它还需要在模块安装上编译的本地库绑定代码。它使用的节点- waf还没有被移植到Windows上。

gm

通用汽车

  • mature
  • 成熟的
  • runs on Windows smoothly
  • 在Windows上运行顺利
  • docs are ok but not thorough: I had to look up into source code to figure out what API is available
  • 文档还可以,但还不够全面:我必须查找源代码以确定哪些API是可用的
  • unfortunately there's no easy way to combine images with gm. Maybe there's some way to achieve that but I haven't found one after two hours spent with it.
  • 不幸的是,并没有简单的方法将图像与gm结合在一起。也许有一些方法可以实现这一点,但是我花了两个小时之后还没有找到。

node-imagemagick

node-imagemagick

  • The official repo has very few basic ImageMagick commands covered but I used this fork (good thing that NPM can pull libraries directly from git repositories). It has bindings for montage which does exactly what I need.
  • 官方的repo几乎没有涉及到基本的ImageMagick命令,但是我使用了这个fork (NPM可以直接从git库中提取库)。它有蒙太奇的绑定,这正是我需要的。
  • ImageMagick is quite slow, though it works on Windows.
  • ImageMagick非常慢,尽管它在Windows上运行。

Node-Vips

Node-Vips

  • Huge plus: it uses an incredible VIPS library which I'm familiar with. VIPS is very fast and optimized for large images. It's very smart about utilizing hardware resources: if your machine has a lot of RAM it'll do all processing in memory but will switch to hard-drive caches if memory is scarce or required for other applications.
  • 巨大的好处:它使用了一个我所熟悉的令人难以置信的vip库。vip是非常快速和优化的大型图像。使用硬件资源是非常明智的:如果您的机器有大量RAM,它将在内存中进行所有处理,但如果内存不足或其他应用程序需要内存,则将切换到硬盘缓存。
  • same as node-canvas it requires Node-Waf so it's not available for Windows yet.
  • 和node-canvas一样,它需要Node-Waf,所以还不能用于Windows。

I also looked at other libraries from the list but most of them are either very immature or do not suit my use case. I would really like to try migrating to either Node-Canvas or Node-Vips when Node-Waf gets ported to Windows but until then I'll stick to node-imagemagick.

我还从列表中查看了其他库,但大多数库要么非常不成熟,要么不适合我的用例。当Node-Waf被移植到Windows时,我真的想尝试迁移到Node-Canvas或node- vip,但在此之前,我将坚持使用node-imagemagick。

#2


5  

I'd strongly advise you to check gm with GraphicsMagick. Stable, feature rich, clean API, great docs, and fast.

我强烈建议你用GraphicsMagick来检查gm。稳定,特性丰富,干净的API,优秀的文档,快速。

And it works both on Windows and Linux / MacOS / BSD / ...

它在Windows和Linux / MacOS / BSD /…

#3


3  

Her is the link to canvas implementation based on GDI+

她是基于GDI+的画布实现的链接。

#1


173  

Answering my own question

回答我的问题

I spent two days digging through Node.js graphics libraries.

我花了两天时间研究Node。js图形库。

node-canvas

node-canvas

  • I tried it first since I'm quite familiar with <canvas> API. It's a huge plus for a library.
  • 我首先尝试了它,因为我非常熟悉 API。这对图书馆来说是一个巨大的好处。
  • it requires Cairo which doesn't have an easy Windows download. I found it in GTK+ distribution though.
  • 它需要Cairo,它没有简单的Windows下载。我在GTK+发行版中找到了它。
  • moreover it needs native library binding code to be compiled on module installation. It uses Node-Waf which hasn't being ported to Windows yet.
  • 此外,它还需要在模块安装上编译的本地库绑定代码。它使用的节点- waf还没有被移植到Windows上。

gm

通用汽车

  • mature
  • 成熟的
  • runs on Windows smoothly
  • 在Windows上运行顺利
  • docs are ok but not thorough: I had to look up into source code to figure out what API is available
  • 文档还可以,但还不够全面:我必须查找源代码以确定哪些API是可用的
  • unfortunately there's no easy way to combine images with gm. Maybe there's some way to achieve that but I haven't found one after two hours spent with it.
  • 不幸的是,并没有简单的方法将图像与gm结合在一起。也许有一些方法可以实现这一点,但是我花了两个小时之后还没有找到。

node-imagemagick

node-imagemagick

  • The official repo has very few basic ImageMagick commands covered but I used this fork (good thing that NPM can pull libraries directly from git repositories). It has bindings for montage which does exactly what I need.
  • 官方的repo几乎没有涉及到基本的ImageMagick命令,但是我使用了这个fork (NPM可以直接从git库中提取库)。它有蒙太奇的绑定,这正是我需要的。
  • ImageMagick is quite slow, though it works on Windows.
  • ImageMagick非常慢,尽管它在Windows上运行。

Node-Vips

Node-Vips

  • Huge plus: it uses an incredible VIPS library which I'm familiar with. VIPS is very fast and optimized for large images. It's very smart about utilizing hardware resources: if your machine has a lot of RAM it'll do all processing in memory but will switch to hard-drive caches if memory is scarce or required for other applications.
  • 巨大的好处:它使用了一个我所熟悉的令人难以置信的vip库。vip是非常快速和优化的大型图像。使用硬件资源是非常明智的:如果您的机器有大量RAM,它将在内存中进行所有处理,但如果内存不足或其他应用程序需要内存,则将切换到硬盘缓存。
  • same as node-canvas it requires Node-Waf so it's not available for Windows yet.
  • 和node-canvas一样,它需要Node-Waf,所以还不能用于Windows。

I also looked at other libraries from the list but most of them are either very immature or do not suit my use case. I would really like to try migrating to either Node-Canvas or Node-Vips when Node-Waf gets ported to Windows but until then I'll stick to node-imagemagick.

我还从列表中查看了其他库,但大多数库要么非常不成熟,要么不适合我的用例。当Node-Waf被移植到Windows时,我真的想尝试迁移到Node-Canvas或node- vip,但在此之前,我将坚持使用node-imagemagick。

#2


5  

I'd strongly advise you to check gm with GraphicsMagick. Stable, feature rich, clean API, great docs, and fast.

我强烈建议你用GraphicsMagick来检查gm。稳定,特性丰富,干净的API,优秀的文档,快速。

And it works both on Windows and Linux / MacOS / BSD / ...

它在Windows和Linux / MacOS / BSD /…

#3


3  

Her is the link to canvas implementation based on GDI+

她是基于GDI+的画布实现的链接。