Download specific part of a canvas as image

44 views Asked by At

I am using react-konva to work with images on a canvas. Now almost everything is working, except that I want to download part of the canvas as image.

I have look at the docs react-konva and it seems I can only download the whole canvas as image or use an external library to export to a pdf (which does allow me to set a specific location and size). But that is not an image.

I want to be able to give a specific location and size of the canvas to generate an image.

Please help.

1

There are 1 answers

3
lavrton On BEST ANSWER

You can export part of the canvas. When you get reference to the Konva.Stage instance you can use stage.toDataURL() method for export. That method has arguments to control position and size:

stageRef.current.toDataURL({ x: 10, y: 10, width: 1000, height: 1000 })