Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

svg - rsvg doesn't render linked images

I use the python rsvg bindings to render an svg image into cairo and save to file, which mostly works. But if the svg file contains a linked image, like so:

<image href="static/usrimgs/tmpDtIKpx.png" x="10" y="10" width="600px" height="400px"></image>

the image doesn't show up in the final file (the rest of the svg renders just fine). The relative path is correct based on where the script is running, but I'm guessing there's some problem with the fact that it would normally be a relative URL, not a relative filepath. How do I get around this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are many factors which must be satisfied for LibRsvg to allow an image resource to be loaded. As of v2.40 these include:

  • the image must have an xlink:href attribute
  • that attribute must contain a full, valid URI
  • the scheme can be data:// or file://
  • file:// paths must be absolute
  • file:// paths must be in or below the path of the SVG source file (after any symlinks have been dereferenced)

Note that if input is passed to rsvg-convert via stdin, then no paths count as subdirectories of the input file and all file:// images will be denied.

rsvg-convert < input.svg > output.png  # images denied

rsvg-convert -o output.png input.svg  # images allowed

The code governing image URL resolution can be found in the LibRsvg source in rsvg-base.c, function _rsvg_handle_allow_load.

To add a debugging notification to rsvg-convert when image loading fails, one can append

#define G_ENABLE_DEBUG

to config.h in the source and recompile.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...