Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize the canvas with fabric js [duplicate]

The application lets user save the designs and post it so other users can view it later.

The original canvas saved with the proportions of width=700 and height=600. But when displaying the canvas, I want to resize the canvas to fit into dimensions of (350,300). half of the original. But if I directly apply those dimensions and load width setWidth() and setHeight() it loads with original proportions.

All I want is to display the canvas with new dimensions.

like image 545
Rohan210 Avatar asked Mar 23 '13 10:03

Rohan210


1 Answers

If you are using the library fabric.js, that's not enough.

Considering that 'canvas' is the fabric.js instance object, you should do this to avoid distorsion artifacts:

canvas.setWidth( <desired width> );
canvas.setHeight( <desired height> );
canvas.calcOffset();
like image 94
JR. Avatar answered Sep 19 '22 16:09

JR.