How to write a NativeImage into a file?


#1

I’m having trouble trying to save images from the user’s clipboard into a file. I can read an image from the clipboard as a NativeImage, but how can I export it (or .toPng():s Buffer) into a png file?

Thanks in advance!


#2

You’ll have to use node’s fs module to do so


#3

Thanks a lot!


#4

Still having a small problem regarding transparency: it says in NativeImage’s documentation that PNG format supports transparency, however when I use the following code transparent areas are turned white:

fs.writeFile('tempimage.png', clipboard.readImage().toPng(), function (err) {
            if (err)
                throw err;
            console.log('It\'s saved!');
        });

Any idea what could cause this?


#5

Might be something to ask to @zcbenz!