【发布时间】:2014-02-15 09:29:38
【问题描述】:
这段代码用于根据设置的高度和宽度参数创建动态图像..说 localhost:3000/50/50 将给出宽度为 50 和高度为 50 的图像..我正在使用我得到的这段代码来自 github..我已经在我的系统中安装了 imageMagick。
var http = require('http');
var url = require('url');
var fs = require('fs');
var gm = require('gm');
var server = http.createServer(function(request, response){
var url_parts = url.parse(request.url).path.substring(1).split("/");
var width = parseInt(url_parts[0]);
var height = parseInt(url_parts[1]);
var max = Math.max(width, height);
if(!isNaN(width) && !isNaN(height))
{
response.writeHead(200, {'content-type': 'image/png'});
gm('nodejs.png').
resize(max, max).
crop(width, height, 0, 0).
stream(function(err, stdout, stderr){
if(err) {
console.log(err)
}
else {
stdout.pipe(response);
}
});
}
else {
response.writeHead(400, {'content-type' : 'text/plain'});
response.end();
}
})
.listen(3000);
这是我得到的错误
events.js:72 投掷者; // 未处理的“错误”事件 ^ 错误:生成 ENOENT 在 errnoException (child_process.js:980:11) 在 Process.ChildProcess._handle.onexit (child_process.js:771:34)
文件nodejs.png和项目在同一个目录下,我做错了什么?
【问题讨论】:
-
能否请您发布完整的错误消息并在您的代码中找到错误行?