Page 1 of 1

Grow canvas size of svg

Posted: 2018-03-22T06:05:40-07:00
by hellocatfood
I have a folder of SVG files containing artwork generated automatically via a script. Objects within that file sit outside of the canvas size. An example is below. It's a screenshot from Inkscape and so the black line just shows the size of the canvas.

Image

I want to use imagemagick to convert the SVG to a png and grow the canvas size from the centre so that it renders artwork that sits outside the boundaries of the canvas set in the SVG file. For example, if I render from IM or Inkscape using the canvas size I get this.

Image

I want IM to render this:

Image

I've tried using -extent together with -gravity but I get this.

Image

Is this possible with IM?

Re: Grow canvas size of svg

Posted: 2018-03-22T09:02:19-07:00
by fmw42
Post your SVG file so others can test with it.

Can you not just edit the SVG file to change the bounding box?

Re: Grow canvas size of svg

Posted: 2018-03-22T09:28:44-07:00
by hellocatfood
fmw42 wrote: 2018-03-22T09:02:19-07:00 Post your SVG file so others can test with it.

Can you not just edit the SVG file to change the bounding box?
I'm away from my main computer at the moment but can't attach it but here are another set of SVGs where I have the same problem. https://www.dropbox.com/s/mjj7yq2xcnfkkhi/svgs.zip?dl=0

I have around 500 of these SVGs and so going in to each file and setting the bounding box manually would be very time consuming, hence why I'm looking for an automated way to do this. I don't mind if I can't modify the actual SVG in IM but if I can at least render the file with a different bounding box size then that would work.

Re: Grow canvas size of svg

Posted: 2018-03-22T09:50:04-07:00
by fmw42
I do not see any canvas offsets in the verbose information that would let you expand the canvas. So I am not sure that you can do that in Imagemagick. But I am not an SVG expert. Perhaps one of the other users might be able to help further.

Re: Grow canvas size of svg

Posted: 2018-03-22T15:58:10-07:00
by snibgo
IM tells the renderer, which might be Inkscape, to render the page. If parts of a drawing are outside the page, they won't be rendered. But Inkscape can be told to render the drawing, see https://inkscape.org/en/doc/inkscape-man.html "--export-area-drawing".

I expect delegates.xml can be edited to include this.

Re: Grow canvas size of svg

Posted: 2018-03-22T21:58:19-07:00
by snibgo
Strangely, inserting "--export-area-drawing" in delegates.xml doesn't change the output. Unless you have a burning desire to use IM, I would do the job directly with Inkscape:

Code: Select all

"inkscape" "file_003.svg" --export-area-drawing --export-png="i.png" --export-dpi="90,90" --export-background="rgb(100%,100%,100%)" --export-background-opacity="1"
Put that in a shell for loop for the 500 SVG files, job done. If you then need to process the PNG files with IM, you can do that, of course.

Re: Grow canvas size of svg

Posted: 2018-03-23T08:02:22-07:00
by hellocatfood
Thanks for that, although I don't necessarily want to render the whole drawing, just a specific area different from the area already set within the SVG file.