Grow canvas size of svg

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Grow canvas size of svg

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Grow canvas size of svg

Post 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?
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: Grow canvas size of svg

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Grow canvas size of svg

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Grow canvas size of svg

Post 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.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Grow canvas size of svg

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: Grow canvas size of svg

Post 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.
Post Reply