Javascript 我应该使用哪个库来处理 Node.JS 上的服务器端图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10692075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 02:32:03  来源:igfitidea点击:

Which library should I use for server-side image manipulation on Node.JS?

javascriptimagenode.jsimage-processingimage-manipulation

提问by Andrew Андрей Листочкин

I found a quite large list of available librarieson 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. put them onto one big canvas
  3. crop and mask them a bit
  4. apply a filter or two
  5. Resize the final image and give a link to it
  1. 从外部资源加载一些图像到服务器
  2. 把它们放在一张大画布上
  3. 裁剪并稍微掩盖它们
  4. 应用一两个过滤器
  5. 调整最终图像的大小并提供链接

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

如果 node 包在 Linux和 Windows上都可以工作,那么大加分。

回答by Andrew Андрей Листочкин

Answering my own question

回答我自己的问题

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

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

node-canvas

节点画布

  • I tried it first since I'm quite familiar with <canvas>API. It's a huge plus for a library.
  • it requires Cairo which doesn't have an easy Windows download. I found it in GTK+ distribution though.
  • 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.
  • 我首先尝试了它,因为我对<canvas>API非常熟悉。这对图书馆来说是一个巨大的优势。
  • 它需要没有简单的 Windows 下载的开罗。我在 GTK+ 发行版中找到了它。
  • 此外,它需要在模块安装时编译本机库绑定代码。它使用尚未移植到 Windows 的 Node-Waf。

gm

通用汽车

  • mature
  • runs on Windows smoothly
  • docs are okbut not thorough: I had to look up into source code to figure out what API is available
  • 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.
  • 成熟
  • 在 Windows 上流畅运行
  • 文档是好的,但不彻底:我不得不寻找到源代码,以弄清楚什么API可用
  • 不幸的是,没有简单的方法将图像与 gm 结合起来。也许有某种方法可以实现这一目标,但在花了两个小时之后我还没有找到。

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 montagewhich does exactly what I need.
  • ImageMagick is quite slow, though it works on Windows.
  • 官方存储库几乎没有涵盖基本的 ImageMagick 命令,但我使用了这个 fork(NPM 可以直接从 git 存储库中提取库)。它具有montage完全符合我需要的绑定。
  • ImageMagick 速度很慢,但它可以在 Windows 上运行。

Node-Vips

节点 Vips

  • Huge plus: it uses an incredible VIPS librarywhich 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.
  • same as node-canvas it requires Node-Waf so it's not available for Windows yet.
  • 巨大的优势:它使用了一个我熟悉的令人难以置信的VIPS 库。VIPS 速度非常快,并且针对大图像进行了优化。利用硬件资源非常聪明:如果您的机器有大量 RAM,它将在内存中完成所有处理,但如果内存不足或其他应用程序需要内存,则会切换到硬盘缓存。
  • 与 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-Vips,但在那之前我会坚持使用 node-imagemagick。

回答by Pierre

I'd strongly advise you to check gmwith 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 / ...

回答by pastorgluk

Her is the linkto canvas implementation based on GDI+

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