-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node JS Fabric scaling objects issue #4812
Comments
Why you do not do just canvas.setZoom(scale) and try in that way? |
@asturur Because setZoom() doesn't affect the object properties. setZoom() seems to be merely a visual function the user can play with. In fact using setZoom() the saved PNG has all the canvas' objects unchanged. |
is unclear from the issue what is the start design, the desired effect, and the actual behaviour. |
making a png bigger, starting from a design, can be done with toDataUrl using the multiplier option. if the text is misplaced is often fault of nodecanvas text management. |
hmmmmm... so do you think the problem comes from node-canvas? |
OK, I'll try to circumvent the issue. Client side I'll create a new temporary project with all the objects already resized in a new hidden canvas (with the right dimensions) and send this temp project to the server app. It should work (no more rescaling objects server side, just generate the PNG) but before to say "Hurray" I have to check. |
Unfortunately the attempt to circumvent the issue was not successful. :( To try to circumvent the issue, I sent with the browser to the server a project file with all the objects already scaled and positioned for the new canvas dimensions. Next, on the server, I save the canvas using canvas.toDataURL and write the PNG file. Here is an excerpt of the (Ubuntu 16.04) server side NodeJS code:
Now I have no idea where the issue can be. :( |
If someone is interested I created this repo on Github to better explain the problem and to share a couple of nodejs test applications to demonstrate the issues. FYI. I also sent a post in node-canvas github w/o any answer. If this is the real situation, both NodeJs Fabric & Node-Canvas are totally unreliable and unusable for my very simple scopes. Thanks anyway. |
node-canvas is not a canvas, and the part that does not work well is text and patterns. nodecanvas 2.0 works a little bit better text related, but is in alpha. If you want to have a reliable canvas outside the browser, use a real canvas in an headless environment ( chrome or firefox ) |
@asturur Thanks Andrea, I created a Nodejs test app using Puppeteer (headless browser) and Fabric 1.7.20 (no Node version, this is the same version I used client side) and now the PNG is generated PERFECTLY! If someone is interested, I could create a new repo on Github to show the "How-to". |
Hi roberto, if you want to setup an howto from start to end on how to render something using puppeteer that would be a nice addition on fabricjs.com |
i keep the issue closed since is not something i need to fix. |
Ciao Andrea, lo farò sicuramente al più presto. Lasciami solo organizzare l'esempio per bene in modo che sia chiaro e semplice. |
Ciao Andrea, https://github.com/radiolondra/Server-side-FabricJs-using-Puppeteer Waiting for your comments/suggestions. |
Node Fabric version: 2.2.0
I need to scale the objects in the canvas (Textbox and Image derived custom classes) to follow the new canvas width and height assigned in the node app. After this I create a PNG file with the scaled objects.
Note that the Textbox objects have OriginX=left and OriginY=top.
[NodeJS app Code]
ftest.post('/process', function(req, res) {
// fabric & canvas variables come from an included module with functions getFabric() and createNodeCanvas()
var fabric = getFabric(); // var fabric = require('/usr/local/lib/node_modules/fabric').fabric;
var canvas = createNodeCanvas(); // var canvas = new fabric.StaticCanvas();
// SCALING & REPOSITIONING OBJECTS
canvas.forEachObject(function (obj) {
// CREATING PNG FILE
var out = fs.createWriteStream(__dirname + '/mio2.png');
var stream = canvas.createPNGStream();
stream.on('data', function(chunk){
//res.write(chunk);
out.write(chunk);
});
stream.on('end', function() {
res.end();
console.log("Finished!");
});
});
});
});
The problem is that the PNG image (with scaled objects) seems to have all the objects well scaled and positioned BUT one Textbox (and I don't understand why). Its scaled TOP, as reported by the console.log, should be 15 (I suppose from its top but it seems to be from its bottom...?!?!? I'm confused.)
Removing the scaling, everything is well positioned (top/left) but, obviously, not scaled.
In the browser version of the same code, using fabric 1.7.20, the PNG image is created with all the objects correctly scaled and positioned.
Maybe I'm assuming/doing something wrong. Maybe node-canvas does something different. I don't know.
Any idea? Could you helpme?
Thanks
Rob
The text was updated successfully, but these errors were encountered: