So, let's say I have an SVG that looks like this:
<svg width="800" height="600" viewBox="0 0 800 600" style="border: 1px solid blue;">
<path fill="#f00" stroke="none" d="M720 394.5c-27.98 0-51.61-6.96-71.97-18.72-29.64-17.1-52.36-44.37-71.48-75.12-28-45.01-48.31-97.48-71.39-136.52-20.03-33.88-42.14-57.64-73.16-57.64-31.1 0-53.24 23.88-73.31 57.89-23.04 39.05-43.34 91.45-71.31 136.39-19.28 30.98-42.21 58.41-72.2 75.45C195 387.72 171.62 394.5 144 394.5Z"/>
</svg>
As you can see, the path only occupies a portion of the SVG (and viewBox area).
I would like to know how to transform the values in the paths that they fill the viewBox (essentially rescaling and repositioning the values in the path so it fills the entire viewBox).
[UPDATE]
I'm adding a few more specifics...
Take an example - lets say that I'm starting with an SVG with a viewBox like this: 0 0 1600 1600
.
In that SVG, there's a path that occupies the region from 1200,1200
to 1500,1400
. (I.e., the path is 300 x 200).
I would like to be able to extract that path, and add it to a new SVG with a viewBox of 0 0 300 200
.
To do this, the values in the d
attribute need to be modified accordingly - essentially moved 1200 points up and to the left.
Obviously, absolute coordinates would need to change, but relative coordinates would not. (That should be pretty easy).
But I've also got to deal with curves and their control points, which might get a little tricky.
A perfect solution would be able to examine a path, identify the smallest bounding box that could contain it, then adjust all the points so they fit in that bounding box, anchored at 0,0
.
I wouldn't want to scale or stretch the path.
I'm equally happy with a mathematical process or function to do this, or an online tool of some sort.
I realize that I can use an SVG transformation to accomplish this, but I want to be able to change the actual path.
(I.e., I don't want my web page to include "incorrect" data AND a transform to "correct" it; I just want my code to include the "correct" data.)
Is there a way to do this?