4

I have a series of square SVG files that I would like to arrange lengthwise into one super long SVG file.

I attempted to use imagemagick to combine them. Based on this page: http://linux.about.com/library/cmd/blcmdl1_ImageMagick.htm

and this

http://www.imagemagick.org/Usage/compose/

I tried this command

composite 'file1.svg' 'file2.svg' +adjoin 'outputfile.svg'

However, I received the following error message: composite: unrecognized option '+adjoin' @ error/composite.c/CompositeImageCommand/565.

I tried several other imagemagick commands (convert, display), but had no success. How can I combine these files on the command line? Is there an inkscape command that does this?

4
  • Hmm, I could actually see this being impossible due to ID collision as discussed here: inkscape-forum.andreas-s.net/topic/129319 Mar 8, 2012 at 3:46
  • It's not impossible, but the concatenating program would need to keep track of the IDs, and generate new ones if necessary. Mar 8, 2012 at 8:01
  • Fair point, Erik. I suspect, though, that if that was too complicated for the inkscape team, it's more work than I would want to invest myself to accomplish this task. =) Mar 8, 2012 at 20:50
  • Related question: stackoverflow.com/questions/6668616/…
    – halfer
    Mar 8, 2012 at 23:04

2 Answers 2

6

There's currently no convenient way to do this with only the command line and no custom scripting.

Closest pre-written thing I could find currently (4-16-2012) is https://github.com/astraw/svg_stack, which lets you write commands of the form:

svg_stack.py --direction=h --margin=100 red_ball.svg blue_triangle.svg > shapes.svg

to concatenate.

1
  • You can now also install it with pip3 install svg-stack. It does not seem able to resize different sized to a single size unfortunately, they just remain with different sizes. Oct 18, 2021 at 13:04
1

It should be pretty easy if you're willing to use a scripting language. For each file, just add a prefix to all id tags; so in file 1, id="circle" becomes id="file1_circle", and in file 2, id="circle" becomes id="file2_circle".

In most cases you would get away with a trivial search and replace (find id=" and replace it with id="fileX_) although it is possible to have cases where this won't work (specifically if that find string appears in an item of text, for example).

If you want to do this 'the proper way', you'll need an XML parser (such as XMLReader in PHP).

2
  • Isn't there messy meta-stuff at the top of each SVG file to deal with, too? Doctype declarations and whatever? I guess what I'm saying is, isn't there a generic way to do this without cracking open the file? Mar 8, 2012 at 22:53
  • Yes, although it's a trivial matter to drop one of the <?xml ?> declarations and the opening svg tag. It's a good point however - the width and height elements might need to be rewritten in the svg tag, if the second document is to appear outside the bounding box of the first.
    – halfer
    Mar 8, 2012 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.