123

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:

  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

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

3 Answers3

194

Answering my own question

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

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.

gm

  • mature
  • runs on Windows smoothly
  • docs are ok but 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.

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.
  • ImageMagick is quite slow, though it works on Windows.

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.
  • same as node-canvas it requires Node-Waf so it's not available for Windows yet.

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.

Community
  • 1
  • 1
  • 50
    Thank you for coming back to answer your own question. Great write up! – mpen Sep 05 '13 at 23:27
  • On Windows gm seemed a bit slow for me - though I think this is partly down to how long it took to spawn instances of the gm executable. – Gareth Oakley Mar 31 '14 at 13:38
  • 1
    Node-waf has been replaced by node-gyp in the meantime, so installation of node-canvas should be possible on Windows according to https://github.com/LearnBoost/node-canvas/wiki/Installation---Windows – Florian Ledermann Apr 25 '14 at 18:47
  • I haven't confirmed this by testing but it looks like gm does support montage: https://github.com/aheckmann/gm/issues/75 – geoidesic Jun 25 '14 at 19:23
  • 12
    Time changed and NODE-Vips had 1yr+ no update. I recommend to add **Sharp** to the list instead. It uses also VIPS and is activly maintained: https://github.com/lovell/sharp – Simon Fakir Aug 16 '14 at 13:21
  • 6
    For those stepping into this question these days, [LWIP](https://github.com/EyalAr/lwip) is another good alternative. No external dependencies, it relies on a node.js C++ addon. – MaxArt Jan 14 '15 at 23:08
  • Is there a library like LWIP which doesn't have external dependencies but with the feature to draw text over image? @MaxArt – Thellimist Mar 22 '15 at 14:25
  • 2
    https://github.com/lovell/sharp , another node binding for libvips, now works on Windows. – jcupitt May 28 '15 at 11:54
  • I think you can montage now https://github.com/aheckmann/gm#montage – Fabian Rios Aug 30 '16 at 09:01
  • Found Jimp : https://github.com/oliver-moran/jimp looks great on paper, haven't tried it yet. – thomasb Feb 09 '17 at 22:04
  • [jsdom](https://www.npmjs.com/package/jsdom) can give you access to the HTML canvas, from there you should be able to manipulate images on the canvas. [How to](https://www.npmjs.com/package/jsdom#canvas-support) – Get Off My Lawn Sep 07 '18 at 02:25
  • @GetOffMyLawn jsdom uses node-canvas to achieve this so there is no advantage in using jsdom when you can use node-canvas directly instead. – kayahr Feb 09 '23 at 16:32
6

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

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

Pierre
  • 6,084
  • 5
  • 32
  • 52
3

Her is the link to canvas implementation based on GDI+

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
pastorgluk
  • 191
  • 1
  • 1
  • 7
  • 1
    I can't get this thing to run at all. I just get "%1 is not a valid Win32 application" as soon as I require it. – mpen Oct 30 '13 at 01:53