1
  • I am using fabric version '2.2.0'.
  • while creating an image object pass top, left, width, height.

const imageobj = new fabric.Image(image, {'top': 50, 'left': 50, 'width': 300, 'height': 300});

  • width / height values passed to initialize the image object are used in the image.
  • But the image does not fit to the full width/height when the image's width/height is less than the width/height values passed to initialize the object
  • If the actual image's width/height is more than the width/height passed to initialize the object, the image is cropped

I want the image to fit in given width/height; but the scaleX/scaleY should not be changed. It should always be 1.

I understand there is a breaking change with fabric.image from Fabric.js V 2.0 http://fabricjs.com/v2-breaking-changes

  • I have changed the fabric.Image.fromObject() as suggested in the above link. But that does not affect setting width/height during image creation.

In fabricjs version 1.7.19, the full image is fit in the given width/height. I want the similar behaviour with fabric.js2.2.0

Hema
  • 11
  • 2
  • u need to use scaleX and scaleY to get the desired width and height respectively. And you no need to change `fabric.Image.fromObject()` – Durga Mar 19 '18 at 08:20

0 Answers0