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.
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.
I want IM to render this:
I've tried using -extent together with -gravity but I get this.
Is this possible with IM?
Grow canvas size of svg
- hellocatfood
- Posts: 44
- Joined: 2010-01-01T13:29:41-07:00
- Authentication code: 8675309
- 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 your SVG file so others can test with it.
Can you not just edit the SVG file to change the bounding box?
Can you not just edit the SVG file to change the bounding box?
- hellocatfood
- Posts: 44
- Joined: 2010-01-01T13:29:41-07:00
- Authentication code: 8675309
Re: Grow canvas size of svg
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Grow canvas size of svg
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Grow canvas size of svg
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.
I expect delegates.xml can be edited to include this.
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Grow canvas size of svg
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:
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.
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"
snibgo's IM pages: im.snibgo.com
- hellocatfood
- Posts: 44
- Joined: 2010-01-01T13:29:41-07:00
- Authentication code: 8675309
Re: Grow canvas size of svg
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.