Skip to content
Advertisement

Node.JS JavaScript buffer to image conversion not a valid bitmap file

I’m trying to transfer an image file data from one node.js script to another.

I read the image file in ‘parameter.js’ using ‘readfilesync’, then transfer it to another script ‘convert.js’.

convert.js is meant to re-convert the file data back to an image using WriteFile – and it seems to do a good job.

However, when I try to open the newly created file, I get the error like;

This is not a valid bitmap file, or its format is not currently supported.

Could you help me spot the problem?

Thanks for your help!

parameter.js:

JavaScript

convert.js:

JavaScript

Advertisement

Answer

Converted the entire operation into a simple read and write ‘binary’ format.

Finally worked!

Here’s the code:

parameter.js:

JavaScript

convert.js:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement