I am using fabricjs to render images but the images that I have are very large near to 5 MB or even more.
For example I have a image having 2130*1800 (width*height)
and my canvas width and height ,that I can afford at max is 90%
of window.width*90%
of window.height
.
How can I do that ?
To fit an image to the canvas use the min fitting scale. May result in some empty regions on the canvas.
To fill the canvas with an image mainting aspect (truncates the image) use the max scale.
To just fill the canvas with the image ignoring aspect.
EDIT: I forgot to add..
To set the canvas to the image scale allowing you to draw on the canvas in the image coordinate system.
Here is the jsFiddle example : https://jsfiddle.net/CanvasCode/7oghuwe2/3/
Javascript
Basically you need to calculate what the width would be if you scaled the image by the canvas height and what the height would be if you scale the image by the canvas width, and which ever is smaller, then you scale by that dimension.