stackers stackers - 1 year ago 85
Node.js Question

Send image generated with node-gd to client

I am trying to dynamically generate images using node-gd. My application is node.js/express.

This code successfully generates an image:

//create image
var gd = require('node-gd');
var img = gd.createSync(200, 80);
img.colorAllocate(0, 255, 0);

img.savePng('../test.png', 0, function(error) {
if (error) throw error;

But it saves the image to a file. I don't necessarily want to keep the generated images, just send it to the client.

I was hoping I could just do


But that just returns an object with metadata about the image.

Ben Ben
Answer Source

Would Express's res.sendFile method work for you?


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download