psd-parser icon indicating copy to clipboard operation
psd-parser copied to clipboard

saveAsPng 方法是否支持promise 或者完成回调?

Open luciy opened this issue 8 years ago • 1 comments

saveAsPng 方法是否支持promise 或者完成回调?

luciy avatar Jun 22 '16 09:06 luciy

可以对channelImage.js文件的saveAsPng方法进行下面改动来支持

    layer.saveAsPng = function(output, callback){
        var self = this;
        self.parseImageData();
        var png = new PNG({
            width: self.width,
            height: self.height,
            filterType: 4
        });
        if(self.pixelData){
            png.data = self.pixelData;
            var chunks = [];
            png.pack().on('data', (chunk) => {
                chunks.push(chunk);
            }).on('end', () => {
                var result = Buffer.concat(chunks);
                callback && callback(result);
            }).pipe(fs.createWriteStream(output));
        } else {
            throw 'Not support the colorMode'
        }
    };

kevinkindom avatar Sep 09 '16 12:09 kevinkindom