首页 > 解决方案 > 如何对使用 filestream 和 pngjs 创建的文件进行处理?

问题描述

我需要对 pngjs 和 fs.createWriteStream 创建的图像做一些事情

我尝试使用on finish,但它不起作用

这是来自 pngjs 页面的一个简单示例:

var fs = require('fs'),
PNG = require('pngjs').PNG;


fs.createReadStream('in.png')
    .pipe(new PNG({
        filterType: 4
    }))
    .on('parsed', function() {

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

                // invert color
                this.data[idx] = 255 - this.data[idx];
                this.data[idx+1] = 255 - this.data[idx+1];
                this.data[idx+2] = 255 - this.data[idx+2];

                // and reduce opacity
                this.data[idx+3] = this.data[idx+3] >> 1;
            }
        }

        this.pack().pipe(fs.createWriteStream('out.png').on('finish', function(){
//get image and proccess it to another proccess
// it got error file not found
      });
    });

它得到错误文件未找到如何解决这个问题?

标签: node.jspng

解决方案


推荐阅读