21

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.

Rohan210
  • 825
  • 2
  • 14
  • 35

2 Answers2

108

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();
JR.
  • 1,401
  • 1
  • 11
  • 9
-16

Previously answered here.

I'm not sure what you've been trying, but

var canvas = document.getElementsByTagName('canvas')[0];
canvas.width  = 800;
canvas.height = 600;

should work fine.

Community
  • 1
  • 1
Kat
  • 4,645
  • 4
  • 29
  • 81