Page 1 of 1

Are svg relative paths supported

Posted: 2015-01-05T19:20:49-07:00
by Danack
Hi,

Are relative paths for linking images in SVG files supported?

For example given the two input files "subdir/red.svg":

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100" height="100" viewBox="0 0 100 100" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="80" height="80" fill="red"/>
<image x="30" y="30" width="40" height="40" xlink:href="green.svg" preserveAspectRatio="xMidYMid meet"/>
</svg>
and "subdir/green.svg":

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100" height="100" viewBox="0 0 100 100" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="80" height="80" fill="green"/>
</svg>

Running the command `convert subdir/red.svg test.png` in the directory above these files, gives the error:
"convert: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2709."
Changing the "subdir/red.svg" file to:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100" height="100" viewBox="0 0 100 100" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="80" height="80" fill="red"/>
<image x="30" y="30" width="40" height="40" xlink:href="file:./green.svg" preserveAspectRatio="xMidYMid meet"/>
</svg>
which I believe is the correct format for relative file paths, gives the error:
convert: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no data returned `file:./green.svg' @ error/url.c/ReadURLImage/265.
So I'm guessing they're not currently supported. Is that just because it's not supported or a bug?

Re: Are svg relative paths supported

Posted: 2015-01-05T20:59:53-07:00
by fmw42
This command works OK for me on Mac OSX Snow Leopard with IM 6.9.0.3 Q16 from my home directory. In fact I can put the file in a folder on the desktop and add that to path and it works fine also.

Code: Select all

convert desktop/puzzle_tile_new.svg puzzle_tile_new.png
Check your directory permissions.

Re: Are svg relative paths supported

Posted: 2015-01-06T15:18:38-07:00
by Danack
I have checked my directory permissions. I can't see a problem with them.

I have put the exact code I'm using to test with below. This is on Centos 6.4

Code: Select all


read -d '' red << EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100" height="100" viewBox="0 0 100 100" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="80" height="80" fill="red"/>
<image x="30" y="30" width="40" height="40" xlink:href="green.svg" preserveAspectRatio="xMidYMid meet"/>
</svg>
EOF

read -d '' green << EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100" height="100" viewBox="0 0 100 100" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="80" height="80" fill="green"/>
</svg>
EOF

mkdir "svgSubDir"

echo $red > "svgSubDir/red.svg"
echo $green > "svgSubDir/green.svg"

convert svgSubDir/red.svg test.png

# output is:
# convert: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2709.

cd svgSubDir

convert red.svg testInSubdir.png

# output is:
# convert: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2709.
The command works fine when run in the sub-directory.

Re: Are svg relative paths supported

Posted: 2015-01-06T15:35:30-07:00
by snibgo
When reporting an SVG problem, it helps if you say which SVG renderer you are using. "-verbose" will tell you.

For me, IM v6.9.0-0 on Windows 8.1, the renderers Inkscape and RSVG work fine. MSVG doesn't, giving

Code: Select all

convert.exe: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2709.
Of the three, MSVG is usually the flakiest.

Re: Are svg relative paths supported

Posted: 2015-01-06T15:51:22-07:00
by fmw42
For your green svg code:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="100" height="100" viewBox="0 0 100 100" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="80" height="80" fill="green"/>
</svg>
The following both work for me on IM 6.9.0.3 Q16 Mac OSX Snow Leopard with delegates

libxml @1.8.17_0 (active) for MSVG
librsvg @2.40.2_0+viewer (active) for RSVG

Code: Select all

convert MSVG:green.svg green_msvg.png

Code: Select all

convert RSVG:green.svg green_rsvg.png
Check what delegates you have installed for reading and writing SVG files. It should be listed in

convert -version

on current versions of IM.

What version of IM and platform are you using?



Also check your delegates.xml file to see what "command" tool is being used if you do not preface the file with MSVG or RSVG or INKSCAPE. Perhaps it wants one that is not installed. Mine says


<delegate decode="svg" command=""rsvg-convert" -o "%o" "%i""/>

<delegate decode="svg:decode" stealth="True" command=""inkscape" "%s" --export-png="%s" --export-dpi="%s" --export-background="%s" --export-background-opacity="%s" > "%s" 2>&1"/>

Re: Are svg relative paths supported

Posted: 2015-01-06T15:56:39-07:00
by dlemstra
snibgo wrote: For me, IM v6.9.0-0 on Windows 8.1, the renderers Inkscape and RSVG work fine. MSVG doesn't, giving

Code: Select all

convert.exe: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2709.
Of the three, MSVG is usually the flakiest.
You are correct this looks like an issue in the MSVG reader, we are investigating it.

Re: Are svg relative paths supported

Posted: 2015-01-06T16:24:34-07:00
by fmw42
Must be windows issue, since it works fine for me on my Mac using

Code: Select all

convert MSVG:green.svg green_msvg.png

Re: Are svg relative paths supported

Posted: 2015-01-06T17:53:25-07:00
by snibgo
But the problem occurs (for me) when both red.svg and green.svg are in a subdirectory of the current directory, and the command is:

Code: Select all

convert MSVG:subdir/red.svg test.png
red.svg, not green.svg.

EDIT to add: the parser should read red.svg, see

Code: Select all

xlink:href="green.svg"
and look for green.svg in the same directory as red.svg. I suspect it is looking in the current directory, instead.

Re: Are svg relative paths supported

Posted: 2015-01-06T18:06:44-07:00
by fmw42
Sorry, I forgot about the subdirectories. Nevertheless, the basic convert commands work fine for me on my Mac with subdirectories.

Code: Select all

convert MSVG:desktop/test/green.svg green_msvg.png

Code: Select all

convert RSVG:desktop/test/green.svg green_rsvg.png
Does quoting the input help on Windows?

Re: Are svg relative paths supported

Posted: 2015-01-06T18:18:55-07:00
by snibgo
Yeah, but what about converting red.svg?

For me, quoting at the command line makes no difference. I wouldn't expect it to.

Re: Are svg relative paths supported

Posted: 2015-01-06T20:59:57-07:00
by fmw42
Yes, snibgo, you are right. It does not work with MSVG

This fails with MSVG

Code: Select all

convert MSVG:desktop/test/red.svg red_msvg.png
convert: unable to open image `green.svg': No such file or directory @ error/blob.c/OpenBlob/2701.

But this works with RSVG

Code: Select all

convert RSVG:desktop/test/red.svg red_rsvg.png

I thought the red and green were the same apart from the color (from too cursory a look), but I see now that red has a link to green.

Code: Select all

xlink:href="green.svg"
I suspect you are right about MSVG in that the path indicates the current directory where the command is initiated rather than the directory in the path in the command.

Changing the href to

Code: Select all

xlink:href="desktop/test/green.svg"
allows it to work for me with MSVG. So I think that confirms that MSVG is looking to current directory from which the command is initiated.

Re: Are svg relative paths supported

Posted: 2015-01-06T22:24:12-07:00
by dlemstra
MSVG will only read files from the current directory. We won't add support for relative include paths, you should use rsvg/inkscape as a delegate if you want support for that.

Re: Are svg relative paths supported

Posted: 2015-01-07T11:05:18-07:00
by Danack
Thanks. I am seeing this with Inkscape, but an older version before it was fixed:
https://bugs.launchpad.net/inkscape/+bug/386069

So it's not something to do with ImageMagick.