I am trying to generate bmp
images (graphs) in nodeJS for use in C to display on a low-res display.
Creating the graphs (with d3.js) and converting the svg-code to a bmp works fine (via svg2img and Jimp) and everything appears correctly in the bmp-file.
When I try to display it on the low-res screen, the C code reports that the image height is negative and fails. Now I read that bmp's can be stored top-to-bottom or bottom-to-top (here for example).
In which direction does Jimp work and how could it be reversed?
I have converted the bmp that I generated with Jimp again (using XnConvert) and tried the resulting bmp, which did successfully display on the low-res screen.
In node:
svg2img(body.select('.container').html(), function(error, buffer) {
//returns a Buffer
fs.writeFile('foo1.png', buffer, function(){
Jimp.read('./foo1.png')
.then(image => {
// Do stuff with the image.
image.background(0xffffffff).resize(1200, 500);
image.dither565();
image.write("./public/test.bmp"); // save
})
.catch(err => {
// Handle an exception.
res.send("error1");
});
});
});
In the C-script logs:
BMP_cfSize:1800054
BMP_cfoffBits:54
BMP_ciSize:40
BMP_ciWidth:1200
BMP_ciHeight:-500 <---------------------
//etc.
*****************************************
total_length:1800000,1800000
bytesPerLine = 3600
imageSize = -1800000
Is there a way to revert the order in Jimp? Or am I missing something else? Or would it be easier to try to revert the order in the C-library (I'm not very good with C)?
As pointed out in the comments, making the negative value positive in the bmp-js library that Jimp uses in this line flipped the image but also solved the issue with the C library that required that order.
Using image.flip(false, true) in Jimp, I could keep the correct orientation in the final result.
Issue reported in the bmp-js GitHub.