I am trying to make resizable image with content fully fitted in rect. I found solution how to emulate object-fit: cover, but I need contain. I made some solution:
const width = size.width;
const height = size.height;
var scalex = image.width / width;
var scaley = image.height / height;
var scale = Math.max(scalex, scaley);
return {
cropWidth: width * scale,
cropHeight: height * scale,
};
But it not centered the image inside
Have any ideas how to make it centered?
You can't do that with just
Konva.Image
and crop. Konva can cut content with cropping. But it can't render it with empty spaces. For that case, we can use external canvas.