How to work with units like inch & mm in fabric js

最后都变了- 提交于 2020-02-03 10:02:41

问题


I am working on a fabric js application & i need work with measurement units like inches & mm
I tried this code & it display blank
So my question is how work with units like inch & mm in fabric js

a = new fabric.Rect({ 
            top:0,
            left:0 ,
            fill: '#000',
            width: 50mm,
            height: 50mm,
           
        });
b = new fabric.Rect({   
            top:0,
            left:200,   
            fill: '#000',
            width: 1in,
            height: 1in,
           
        });
    canvas.add(a, b);
<canvas id='canvas' width="500" height="400" style="border:#000 1px solid;"></canvas>

回答1:


fabricjs works in pixels. There is a function: fabric.util.parseUnit() that can parse inches, mm, pixels, points.

    a = new fabric.Rect({ 
                top:0,
                left:0 ,
                fill: '#000',
                width: fabric.util.parseUnit('50mm'),
                height: fabric.util.parseUnit('50mm'),

            });
    b = new fabric.Rect({   
                top:0,
                left:200,   
                fill: '#000',
                width: fabric.util.parseUnit('1in'),
                height:  fabric.util.parseUnit('1in'),
            });
canvas.add(a, b);


来源:https://stackoverflow.com/questions/33475784/how-to-work-with-units-like-inch-mm-in-fabric-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!