Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set height and width of image in fabric.js?

Tags:

fabricjs

I had loaded image in canvas using fabric.Image.fromURL and working fine with default image width and height. Now I want to minimize width and height of an image. How to do this?

Thanks in advance.

like image 955
user1584122 Avatar asked Sep 12 '12 13:09

user1584122


1 Answers

We can use scalex / scaley to set height / width as below.

fabric.util.loadImage(imgsrc, function (img) {
    var legimg = new fabric.Image(img, {
        left: 30,
        top: marker.top,
        scaleX: 20 / img.width,
        scaleY: 20 / img.height
    });
    canvas.add(legimg);
    canvas.renderAll();
});

Thanks

like image 185
Frederic Anand Avatar answered Sep 28 '22 02:09

Frederic Anand