Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image manipulation in NodeJS with base64 image data

I have a nodejs server that receives images encoded in base64 through a websocket. I would like to do some image manipulation on those images and send them back. I searched a little bit on the net to find some library to help me doing this, but all I could find were libraries that take images stored somewhere in the server side, do the manipulation and save back the image. Apparently all of them take as input a string containing the filename of the image, so I guess under the hood they are fetching the image manually through a file stream.

My question is, is there a library that may help me working directly on base64 data (that is, passing the data as input to the functions) or should I save every time the image on the server, modify it and send it back? I would rather not go with the latter because I'm working on some high-performance application, and all this saving/loading looks a waste of cycles. Otherwise, do you see some other way I could achieve this (that is, getting the image file without saving and loading it back, for example)?

Thanks.

like image 301
Masiar Avatar asked Nov 03 '22 12:11

Masiar


1 Answers

Work with Buffers.

var img = new Buffer(img_string, 'base64');
// Work with your images like other tutorials do.
like image 92
Florian Margaine Avatar answered Nov 11 '22 04:11

Florian Margaine