11

I'd like to create an application using node.js which creates an image. In the image I'd like to programmatically draw circles, lines or any function f(x) (well I could draw that function by adding points at some coordinates). I'd like to know which node.js modules I should use, or if there is something created for this.

In other words I need to draw a given mathematical functions and export it to an image file.

Thanks.

1
  • At a basic level, you'll need something like ImageMagick. Sounds to me though that you might want a higher level library on top of that for plotting. Commented Nov 3, 2012 at 19:35

1 Answer 1

13

Have a look at node-canvas which is a canvas implementation for Node.js

Source code example:

var Canvas = require('canvas')
  , canvas = new Canvas(200,200)
  , ctx = canvas.getContext('2d');

ctx.font = '30px Impact';
ctx.rotate(.1);
ctx.fillText("Awesome!", 50, 100);

var te = ctx.measureText('Awesome!');
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.beginPath();
ctx.lineTo(50, 102);
ctx.lineTo(50 + te.width, 102);
ctx.stroke();

console.log('<img src="' + canvas.toDataURL() + '" />');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.