gliffy / canvas2svg

Translates HTML5 Canvas draw commands to SVG
MIT License
691 stars 157 forks source link

Is is possible to convert only a part of the canvas? #87

Open FrankDaze opened 2 years ago

FrankDaze commented 2 years ago

Is is possible to convert only a specific area of the canvas?

This is a screenshot of a tool where you can select the area that you like to export.

image

I like to build something similar in my own tool.

Thanks in advance Frank

murkle commented 2 years ago

Yes, just use the standard canvas clipping operations

FrankDaze commented 2 years ago

If I use clip() everything is only drawn inside the clip path, but if I export the canvas, it's still the whole canvas and not only the part in the clip path.

Correct me if I'm wrong.

murkle commented 2 years ago

Try it - you can probably set the bounding box and/or the origin in the SVG

FrankDaze commented 2 years ago

my idea is now to translate the selected / clipped area to the upper left corner and set the canvas size to the clip size.

I think then I get only the the objects which are drawn in the selection and the file is really small.

thanks for brainstorming

jayykumar commented 2 years ago

@FrankDaze I m also looking for similar solution. I was able to clip the region, but not able to translate to desired location.could you please shared code used for your logic.