I am using headless-gl to run webGL on Node.js, creating an image dynamically on server. Once created, the image is to be stored in database (MongoDB), before user accessing the image again via API.
Below is the part where the image is generated:
var pixels = new Uint8Array(width * height * 4)
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
The pixels are then converted to base64 (since this seems to be the recommended way to be loaded by Image in client HTML).
var base64Image = new Buffer(pixels, 'binary').toString('base64');
However, the string produced by this buffer can't be decoded to produce an image. May be pixels is not 'binary' type? Or should I just save the pixel string in the database and try to redraw the pixel in canvas pixel by pixel in client (I don't think this is the best way) ?