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?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • Hmm, I could actually see this being impossible due to ID collision as discussed here: http://inkscape-forum.andreas-s.net/topic/129319 – Mittenchops Mar 08 '12 at 03:46
  • It's not impossible, but the concatenating program would need to keep track of the IDs, and generate new ones if necessary. – Erik Dahlström Mar 08 '12 at 08: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. =) – Mittenchops Mar 08 '12 at 20:50
  • Related question: http://stackoverflow.com/questions/6668616/svgexception-on-merge-svgs-in-a-new-one – halfer Mar 08 '12 at 23:04

2 Answers2

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.

Mittenchops
  • 18,633
  • 33
  • 128
  • 246
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).

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 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? – Mittenchops Mar 08 '12 at 22:53
  • Yes, although it's a trivial matter to drop one of the `` 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 08 '12 at 23:00