I am facing some challenges while scaling a Konva.Image
. I want to scale the image from it's center point. Although I am able to scale it from center but I am not sure whether it is a correct way of doing this or not. Currently it is scaled from it's top-left
corner. To scale the image from center point I am setting it's offset
to center by using image.setOffset()
. But I don't know why it is moving the image. I am doing this:
//setting the offset to center
//but don't know why it's moving the image.
yoda.setOffset({
x: yoda.width() / 2,
y: yoda.height() / 2
});
// setting it's position back to original
// position but don't know why I need to
// adding the offset values
yoda.position({
x: 50 + yoda.width() / 2,
y: 50 + yoda.height() / 2
});
To scale the image I am doing this:
yoda.scale({
x: 0.5,
y: 0.5
});
layer.draw();
Is there any other way to achieve the same? Here's the plunkr to play.