我正在使用https://github.com/aheckmann/gm来调整图片大小。
var gm = require('gm').subClass({ imageMagick: true });
var fs = require('fs');
var dir = __dirname+'/img';
var readStream = fs.createReadStream(dir + '/Desert.jpg');
var writeStream = fs.createWriteStream(dir + '/resize.jpg');
gm(readStream)
.size({bufferStream: true}, function(err, size) {
this.resize(50, 50, '%')
this.write(writeStream, function (err) {
if (!err) console.log('done');
});
});
我正在使用上面的代码调整图像大小....问题是生成了一个空图像,错误信息是{[错误:写EPIPE]代码:'EPIPE',错误:'EPIPE',系统调用: '写'}
答案 0 :(得分:1)
write
方法将字符串作为输出文件名。试试stream
方法:
gm(readStream)
.size({bufferStream: true}, function(err, size) {
this.resize(50, 50, '%')
.stream()
.on('end',function(){
console.log('done');
})
.on('error',function(err){
console.log(err);
})
.pipe(writeStream);
});