在mac os 下测试没有成功: var gm = require(“gm”); var imageMagick = gm.subClass({ imageMagick : true });
imageMagick(224, 144, “#fff”) .fontSize(18) .drawText(10, 25, “GMagick!”) .write('./ImgNumber.png’,callback);
以上代码哪地方出错了。
var gm = require("gm");
var imageMagick = gm.subClass({ imageMagick : true });
imageMagick(224, 144, "#fff")
.fontSize(18)
.drawText(10, 25, "GMagick!")
.write('./ImgNumber.png',function(){}); // bug point
签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3
不行,callback是我传进来的。 问题不是出在这 mac-mrlongtekiMac-mini:test mac-mrlong$ convert b.jpg -gravity southeast -fill black -pointsize 16 -draw “text 5,5 'www.yunzj.net’” c.jpg
convert: delegate library support not built-in none' (Freetype) @ warning/annotate.c/RenderFreetype/1533. convert: Postscript delegate failed
/var/tmp/magick-23599rP_TuIqCrXdh’: No such file or directory @ error/ps.c/ReadPSImage/837.
convert: delegate library support not built-in none' (Freetype) @ warning/annotate.c/RenderFreetype/1533. convert: Postscript delegate failed
/var/tmp/magick-23599xTb_YBMQEKy6’: No such file or directory @ error/ps.c/ReadPSImage/837.
convert: non-conforming drawing primitive definition `text’ @ error/draw.c/DrawImage/3168.
I use this lib https://github.com/aheckmann/gm
win / mac / ubuntu is OK.
签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3
贴出代码,希望大家一起用过gm
// //生成验证码 // //直接生成一个图片到前台 // Gm.ImgNumber('23143’,function(err,stdout){} // if(!err){stdout.pipe(res)} // ); //
exports.ImgNumber=function(text,callback){ var img=imageMagick(214, 44, “#fff”) .fill(“#fff”) .stroke("black", 1) .drawRectangle(2, 2, 210, 40) .autoOrient();
var imgcolor=[“green","blue","black","red”]; for (var i=0;i<20;i++){ img.stroke(imgcolor[parseInt(Math.random()*4)], 1); img.drawLine( parseInt(Math.random()*210+1), parseInt(Math.random()*40+1), parseInt(Math.random()*210+1), parseInt(Math.random()*40+1)); };
img.fontSize(30);
img.stroke(“#ffffff”);
for (var i=0;i<text.length;i++)
{
img.stroke(imgcolor[parseInt(Math.random()4)], 1);
img.drawText(20+i30, 30, text[i]);
};
var filename = ‘./in’ + text + '.jpg’;
img.write(filename,function(err){
if(!err){
var readStream = fs.createReadStream(filename,{flags : 'r’,
encoding : null,
mode : 0666,
autoClose: true
});
callback(err,readStream);
fs.unlink(filename);
}
else{
callback(err);
};
});
//img.stream(callback);
//img.toBuffer(callback);
//.write(writeStream, function (err) { // if (!err) console.log(' hooray! '); //}); }