Inkscape.org
Beyond the Basics Is there a way to call Inkscape from the CLI to crop a SVG file, but maintain the original bounding box?
  1. #1
    visusys visusys @visusys

    I have been using the following in my code (I'm using powershell):

    & "C:\BIN\Inkscape\bin\inkscape.exe" -o $NewFullFilePath -D $NewFullFilePath | Out-Null

    This works fantastically, but it modifies the viewbox of the resulting file. I'd like to have Inkscape resize the artwork to the exact bounds of the artboard / viewbox, leaving the original viewbox values in tact.

    Is this possible? Can someone show me the way?

  2. #2
    inklinea inklinea @inklinea⛰️

    You can change the viewbox in the svg from the command line ( Assuming you do not have nested SVGs )

    inkscape --actions="select-by-element:svg;object-set-attribute:viewBox,0 0 250 500;export-filename:drawing_vb.svg;export-do" ./drawing.svg

    It seem that you want to find the combined bounding box of all elements. Then scale that to match the bounding box.

    I'm not sure if it can be done with the viewbox alone, because it's very likely that the original canvas and the combined object bounding box will have different aspect ratios.

     

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Is there a way to call Inkscape from the CLI to crop a SVG file, but maintain the original bounding box?