I have a fabric js canvas that I allow users to add external images to. Often times the user adds images that are too large to fit the canvas and it's a little difficult for them to re-size them correctly.
I'd like to automatically scale the larger images down so that the image maintains it's aspect ratio but fits on the canvas.
Is there something in the fabric.js api that does this or do I need to calculate a ratio and set the scale x\y?
I've tried this but it distorts the image.
oImg.set({
left: _fabicCanvas.width / 2,
top: _fabicCanvas.height / 2,
scaleY: _fabicCanvas.height / oImg.height,
scaleX: _fabicCanvas.width / oImg.width
});