Site icon Brian Prom Blog

Installing Fabric for NodeJS on Linux

UPDATE June 3rd, 2015

I found that these instructions don’t always work for every distribution of Linux.  I have an alternative set of instructions for installing NodeJS on Linux that has been reliable for two different Linux distributions so far.


 

Over the past few months I’ve been working with the HTML5 Canvas to build a product configurator that allows for multiple images, multiple text elements, a background color or pattern (image), and for one product multiple surfaces.

To implement this, I’m using the Javascript library FabricJS to make working with the Canvas a bit easier.

The Problem:

In my first iteration of the project, I implemented this so that the clients browser would use FabricJS to generate the final output high resolution image and send that to my server for saving and production.  This worked great in my testing.  Until I got random orders that just weren’t right… they looked so odd there was no way a customer would want to order that.

After some research I realized what was happening.  The Canvas was an average size for the browser – say 300px x 200px.  Big enough for the customer to do their work and get an accurate representation of what they will receive.  But what I need for print production on the backend is more like a 2500px x 1600px image.  And Canvas / FabricJS will output this just fine.  The problem is that large image has such a large file size that I was hitting a memory limit of the clients browser – namely iOS devices.  I don’t have any hard proof that Android devices were doing the same as I have limited access to them for testing at this time, but I’m assuming they have the same issue.

The Solution:

Ok, so we’ve identified a huge problem in the implementation of this…. now what?  What is the solution?  To be honest, it was there in the Fabric documentation all along and I kinda chose to ignore it…  Kangax (the creator of FabricJS) talks about how to run your Fabric app on NodeJS towards the end of his tutorial.

Instructions for installing Fabric JS on Linux

How It Works:

NodeJS is a server side scripting language based on Javascript.  It’s a very robust language actually and has a large number of installable modules to extend it’s capability.  So the the setup works like this:

This article is not going to be a full tutorial on how to do that entire process.  I can’t give away all of my code!  But what I will do, is provide you with the setup procedure for NodeJS and Fabric for Node.  I’ve also implemented a NodeJS module called GraphicsMagick for further image manipulation within NodeJS.

Installation Notes

NOTE: If you are installing NodeJS on Debian, please refer to these instructions for installing NodeJS on Debian Squeeze.

Installation Procedure

Assuming that everything went smooth and you didn’t get any errors, you’re all set!  Now lets test it and ensure that this worked as expected.

Testing:

Good To Know Details:

Limitations:

I’m sure there is a bigger list, but at this time I really have only found one real limitation

Resources:

I hope this guide helps someone out there in their setup.  FabricJS and NodeJS are both very powerful tools that help us to take the internet into a very cool direction and are helpful in replacing some of what the boggy Flash did for us in the past.  Documentation exists on the internet, but it’ll never hurt to have more!

Exit mobile version