0

I want to resize a FabricJS canvas and keep the image aspect ratio, i.e. scale the image proportionally in x/y dimensions.

I've tried several approaches but when I resize the canvas and an image is loaded on it, the image gets distorted, and the aspect ratio changes. I'd like the image to be scaled proportionally, or just to maintain the image size and dimensions no matter how I resize the canvas.

It seems that it's a known issue, and a solution is proposed here, but the lockUniScaling method is not available in FabricJS anymore.

I've tried using different parameters like uniformScaling or centeredScaling.

Besides, I've tried using both backstoreOnly and cssOnly options when setting the new canvas dimensions, but none of them work:

fabricCanvas.setDimensions({
    width: "90%",
    height: "90%"
},
{
    cssOnly: true
});
evidalpe
  • 11
  • 3

0 Answers0