18

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
  • 765
  • 2
  • 12
  • 34

2 Answers2

100

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,321
  • 1
  • 10
  • 9
-15

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,605
  • 3
  • 27
  • 79