imgae resize 为什么 上传图片 resize 图片 传10 有1~2次 失败呢?
发布于 11 年前 作者 quanchunlin 7462 次预览 最后一次回复是 10 年前 来自 问答
我用的是 nodejs gm 。 服务器是 linux 装了imagemagick throw err; ^ Error: Command failed: at ChildProcess._spawn.proc.on.onExit (/home/hosting_users/quanchengji/apps/quanchengji_shawn/node_modules/gm/lib/command.js:279:17) at ChildProcess.EventEmitter.emit (events.js:98:17) at maybeClose (child_process.js:735:16) at Process.ChildProcess._handle.onexit (child_process.js:802:5)
而且 出这个错时 有时 还会 重起node 。。 请高手 帮忙。
11 回复
好痛苦 这问题 让我花去 好几天 没能解决。。 没人知道 原因 么 。。。
我也遇见了,求解
没有人 碰见过 这个问题吗?还是 碰见了 没能解决 ? 还是resize 图 使用其它 方法 来实现?
我也用的gm,项目有半年了,到目前为止,没有出现过你的这个问题,能具体点吗?
var filePath = req.files.photo.path, imageName = req.files.photo.name , basePath = path.join(rootDir, ‘/public/uploads/user/’ + id), baseThumbPath = basePath + ‘/thumbs’; fs.readFile(filePath, function (err, data) { //
}); 服务器是 linux , node.js 0.10.21 , imagemagick ,gm (从ng-cordova 上传的 相片) 一开始是 使用了 imagemagick wrapper 也出这个错误 后来 换了 gm 不过同样 出现 相同错误。请高手 帮忙 谢谢。
已经 7天 没能 解决 。苦恼
@quanchunlin 我使用的方式: var gm = require(‘gm’), im = gm.subClass({ imageMagick:true }); im(原图路径).resize(size1,size2).autoOrient().write(新图路径地址,function(err) { … })
这个 方式 我试过了不过还是 出一样错 错误。 所以 我 现在 我又换了 。 gm(filePath).stream(‘JPG’, function (err, stdout, stderr) {
var writeStream = fs.createWriteStream(newPath); stdout.pipe(writeStream);
writeStream.on(‘close’, function () { return cb(null , {photo:imageName}); }); }); 这样 不出 error 可是 偶尔会出现 空白图 。 resize是在 使用 image 服务器的方式 gm(rootImgPath).resize(150, 150).toBuffer(‘JPG’,function (err, buffer) { if(err){ throw err; //return res.sendfile(rootDir + config.defaultImagePath ); } var imageName = imgPath.substr(imgPath.lastIndexOf(’/’)+1); var ext = imageName.split(’.’);
@quanchunlin 这个我也不是很清楚,不过为什么你要先把文件内容读出来,然后再写进文件再进行操作呢,为什么不直接操作上传上来的文件?
现在问题已经 解决了。 谢谢你。不先读 直接 fs.writeFile 不好使。。
请问楼主怎么解决的啊,我也碰到了类似的问题