Fabric.js: scaleToWidth() only by width. Is it possible?

Created on 4 Oct 2017  路  3Comments  路  Source: fabricjs/fabric.js

Hello!
I need to scale image to sertain width and height manually, not by using controls.
But

Scales an object to a given height/width, with respect to bounding box (scaling by x/y equally)

.
Is it possible to scale by one side only?

Most helpful comment

This question would be better on stackoverflow, but you can do it like this:

object.set('scaleX', desiredWidth / object.width)

All 3 comments

Not sure but maybe this can help you?

scaleX :Number
Object scale factor (horizontal)
http://fabricjs.com/docs/fabric.Object.html

Thanks for help willKo. I really can scale by one side! But i need to scale to sertain width or height.

This question would be better on stackoverflow, but you can do it like this:

object.set('scaleX', desiredWidth / object.width)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vivek-KT picture Vivek-KT  路  3Comments

zhangzhzh picture zhangzhzh  路  4Comments

gjijon picture gjijon  路  5Comments

bevacqua picture bevacqua  路  4Comments

semiadam picture semiadam  路  3Comments