SVG: Calculate viewbox depending on path to centre

56 Views Asked by At

I have many SVG files who needs editing so the only polygon they have is nicely centred and fills the screen but I cannot make up my mind on how to calculate the viewbox.

Given the following viewbox, I was calculating the extreme points, which are

min_x=3491.07
min_y=2760.09
max_x=3667.22
max_y=2888.07

I was naive to think, that setting it to (min_x min_y max_x-min_x max_y-min_y) would solve my problem, but it does not.

What is the ideal way to achieve this?

I want to alter the SVG, not alter the website or whatever where I show the svg on

<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" viewBox="2900 2000 2000 2000" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cc="http://creativecommons.org/ns#">
      <g inkscape:groupmode="layer" stroke-width="1" stroke-linejoin="bevel" stroke-linecap="square" inkscape:label="Map 1: fid_44" fill="none" stroke="black" id="Map 1: fid_44" fill-rule="evenodd">
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(1,0,0,1,0,0)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(1,0,0,1,0,0)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g fill-opacity="0" font-weight="400" font-size="83.3333" font-style="normal" fill="#000000" transform="matrix(0.999873,0,0,0.999873,-728.486,-229.753)" font-family="Noto Sans" stroke="none">
          <rect y="0" width="8098" height="5627" x="0"/>
        </g>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(0.999873,0,0,0.999873,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g fill-opacity="1" stroke-width="2" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="#e77148" stroke-opacity="1" transform="matrix(0.999873,0,0,0.999873,-728.486,-229.753)" font-family="Noto Sans" stroke="#232323">
          <path d="M3529.56,2865.68 L3541.4,2872.26 L3554.56,2868.32 L3565.08,2872.59 L3583.28,2888.07 L3595.6,2874.89 L3604.53,2869.36 L3610.48,2879.14 L3624.94,2886.79 L3657.67,2860.01 L3659.33,2861.9 L3665.74,2857.13 L3667.22,2830.65 L3645.51,2828.51 L3598.8,2783.28 L3572.98,2785.26 L3560.81,2776.37 L3553.9,2760.09 L3546.83,2777.52 L3542.06,2777.85 L3523.14,2813.22 L3497.49,2788.05 L3491.07,2798.08 L3512.62,2820.29 L3529.56,2839.53 L3529.56,2865.68" vector-effect="none" fill-rule="evenodd"/>
        </g>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(0.999873,0,0,0.999873,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(1,0,0,1,0,0)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(23.619,0,0,23.619,-728.486,-229.753)" font-family="Noto Sans" stroke="#000000"/>
        <g stroke-width="1" stroke-linejoin="bevel" font-weight="400" stroke-linecap="square" font-size="83.3333" font-style="normal" fill="none" stroke-opacity="1" transform="matrix(1,0,0,1,0,0)" font-family="Noto Sans" stroke="#000000"/>
      </g>
    </svg>

0

There are 0 best solutions below