Skip to content Skip to sidebar Skip to footer

Noise In Png Produced By Pngjs For Nodejs

I want to slice PNG spritesheet to sprites using pngjs v3.3.0 for nodejs. This gives me unxpected noisy background for some of produced sprites. Then I tryed simple script that jus

Solution 1:

The data needs to be initialized. This can be achieved like this (also see https://github.com/lukeapage/pngjs/blob/master/examples/newfile.js):

var fs          = require('fs');
var PNG         = require('pngjs').PNG;
var dstBuffer   = new PNG({ width:50, height:50 });

for (var y = 0; y < dstBuffer.height; y++) {
    for (var x = 0; x < dstBuffer.width; x++) {
        var idx = (dstBuffer.width * y + x) << 2;

        dstBuffer.data[idx] = 255;
        dstBuffer.data[idx + 1] = 255;
        dstBuffer.data[idx + 2] = 255;

        dstBuffer.data[idx + 3] = 255;
    }
}

dstBuffer.pack().pipe(fs.createWriteStream("empty.png"));

Post a Comment for "Noise In Png Produced By Pngjs For Nodejs"