Skip to main content

Fit the Canvas object to the canvas width or height

function fitToScale()
        {
            activeObject = canvas.getActiveObject();
            if (activeObject.width >= activeObject.height) {
                expectedScaleX = (canvas.width - 20) / activeObject.width;
                proportion = expectedScaleX / activeObject.scaleX;
                activeObject.scaleX = expectedScaleX;
                activeObject.scaleY = activeObject.scaleY * proportion;
                horizontal_center_object();
            }
            else {
                expectedScaleY = (canvas.height - 20) / activeObject.height;
                proportion = expectedScaleY / activeObject.scaleY;

                activeObject.scaleY = expectedScaleY;
                activeObject.scaleX = activeObject.scaleX * proportion;
                vertical_center_object();
            }
            canvas.renderAll();
        }

Popular posts from this blog

The old company comeup with new brand MAXBEN - Logo meaning

I am so happy to design this logo for my friend Suresh Mahalingam to boost his paint business to the next level. The first step in his process is logo design. He had a clear idea about his business, processes, pricing and target audience. I just collect all those information from him and created the logo with some appropriate meanings. Check out the logo here