abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
699 stars 61 forks source link

Crop to Content #9

Closed bcongdon closed 4 years ago

bcongdon commented 4 years ago

I've been using vpype a bunch recently, and have really enjoyed it!

One feature request that I have is the ability to "crop to content". i.e. Given an SVG, find the outer bounding rect of all the paths in it, and crop to that bounding box.

abey79 commented 4 years ago

Hey @bcongdon, could you please elaborate on your use case? vpype doesn't explicitly maintain a bounding rect so everything is sort of implicitely always bounded by the extend of the path collection.

bcongdon commented 4 years ago

Hmm... Maybe I'm misunderstanding, but I guess what I'm suggesting is a way to translate the path collection so that the upper-left most point is at (0,0), and the size of the written SVG matches the extent of the path collection.

Does vpype already do this?

abey79 commented 4 years ago

By default, that's exactly the behaviour of the write command. Without option (e.g. vpype [...] write output.svg), the geometry is translated to (0, 0) and the SVG bounds are tightly fitted to the geometries.

In the case where you provide a pagination options (e.g. vpype [...] write --page-format a4 output.svg), then no translation or scaling is applied to the geometry, so it could fall out of SVG bounds. Adding the --center option will translate the geometry to the centre of the page.

The typical workflow is to first scale the geometry to a desired size and then export SVG with pagination option:

vpype [...] scale --keep-proportions --to 15cm 10cm write --page-format a3 --landscape --center output.svg

Note the use of the --to option for the scale command. It resizes proportionally the geometries (proportionally, thanks to the --keep-proportions option) so that it fits an area of defined size.

(If you use this combination often, you'll likely want to learn the short versions of the various options: vpype [...] scale -p --to 15cm 10cm write -lc -p a3 output.svg)

Let me know if this answers your question.

bcongdon commented 4 years ago

Awesome! Thanks for the detailed explanation.