Search code examples
javascriptkineticjs

Kinetic JS - Scale image to fit canvas?


I'm trying to scale an image down to fit the canvas. I know the usual way:

var width = img.width-(img.width-canvas.width);
var height = img.height-(img.height-canvas.height);

But I'm looking to do it with img.setScale(), based on 0 (0%) and 1 (100% of size). I'm not sure how to do that in KineticJS. Any suggestions are appreciated!


Solution

  • @philipp's answer did it:

    scalefactor = desiredSize / size, for both width and height