FabricJS + Node不能通过nodeJs fabric设置backgroundImage
FabricJS + Node not being able to set up backgroundImage via nodeJs fabric
我无法使用节点画布在FabricJs上设置背景,我可能做错了,但我在网上找不到我真正需要做的事情。
我看到的唯一代码是正常的节点,但没有地方教我到底要做什么
因此,当我编写以下代码时,我得到的所有内容都是带有我添加的所有内容的最终图像,除了透明背景。
var out = fs.createWriteStream('public/server/_tempImg/slideTeste.png');
var canvas = fabric.createCanvasForNode(800,450);
var text = new fabric.Textbox('Testing Slide with background', {
fontFamily: 'Arial',
textAlign: "center",
left: 0,
top: 0,
fontSize: 40,
width: 500,
fill: '#000000'
});
canvas.add(text);
canvas.centerObject(text);
canvas.setBackgroundImage('public/img/bg_bookeh1.jpg',
canvas.renderAll.bind(canvas));
var stream = canvas.createPNGStream();
stream.on('data', function(chunk) {
out.write(chunk);
});
stream.on('end', function(data){
//console.log('Salvou imagem');
res.sendStatus(200);
});
我也试过用不同的图像设置它
canvas.setBackgroundImage('http://localhost:3000/img/bg_bookeh1.jpg',
canvas.renderAll.bind(canvas));
我做错了什么?
在通过Node导出图像之前,图像没有加载吗?
这是我得到的图像。一个透明背景的PNG。
输入图片描述
我发现它之前没有加载图像,所以正确的方法是。
var out = fs.createWriteStream('public/server/_tempImg/slideTeste.png');
var canvas = fabric.createCanvasForNode(800,450);
var text = new fabric.Textbox('Testing Slide with background', {
fontFamily: 'Arial',
textAlign: "center",
left: 0,
top: 0,
fontSize: 40,
width: 500,
fill: '#000000'
});
canvas.add(text);
canvas.centerObject(text);
//load the image first
fabric.Image.fromURL('http://localhost:3000/img/bg_bookeh1.jpg', function(myImg){
var stream = canvas.createPNGStream();
canvas.setBackgroundImage(myImg,
canvas.renderAll.bind(canvas));
stream.on('data', function(chunk) {
out.write(chunk);
});
stream.on('end', function(data){
//console.log('Salvou imagem');
res.sendStatus(200);
});
});
真正不同的是用
加载图像fabric.Image.fromURL('http://localhost:3000/img/bg_bookeh1.jpg', function(myImg){
,然后在加载后创建图像。
stream.on('data', function(chunk) {
out.write(chunk);
});
stream.on('end', function(data){
//console.log('Salvou imagem');
res.sendStatus(200);
});
相关文章:
- nodejs-expressjs上传图像并显示它们
- TypeError:在不兼容的接收器nodejs上调用了方法Uint8Array.length
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- NodeJS日期格式不起作用
- Nested Q.all nodejs
- Nodejs API控制器,用于在API之间切换
- 否'访问控制允许来源'标头存在于IISNOde中请求的资源(AngularJS+NodeJs)上
- 如何在大型nodeJS代码的基础上逐步引入typescript
- 在Nodejs中Express输入DEBUG=app时权限被拒绝/bin
- 无法使用nodeJS在html中设置Image src
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- 使用fabric.js从矩形区域获取对象,并将该区域绘制到画布上
- NodeJS API调用中Array中的Push和Pull元素
- 基于api密钥的NodeJS web服务
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- “util.inherits”和在NodeJS中扩展原型之间的区别
- 将一个方法转换为promise:Nodejs
- nodejs中匿名函数的使用
- Node和Nodejs版本不同
- FabricJS + Node不能通过nodeJs fabric设置backgroundImage