简体   繁体   中英

How to concatenate SVG files lengthwise from linux command line?

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?

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM