Reputation: 8168
The minimum width
of the image should be 300
and the height should get scaled proportionately with respect to width.
Suppose the user uploads image size of 5ooX850
, I will use
Img.set({
scaleX: 300 / Img.width,
});
But how to scale image height
with respect to width
?
Upvotes: 8
Views: 13179
Reputation: 3795
Set in image object
/*scaleToWidth(value, absolute)*/
Img.scaleToWidth(300, false);
Upvotes: 8
Reputation: 9690
Scale Y by the same ratio used to scale X
let scale = 300 / Img.width;
Img.set({
scaleX: scale,
scaleY: scale
});
With your example of 500 x 850
, both X and Y would be 3/5
of their original measurements.
Upvotes: 11