rsvg doesn't render linked images

后端 未结 4 698
野的像风
野的像风 2020-12-11 17:43

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:

4条回答
  •  难免孤独
    2020-12-11 18:29

    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.

提交回复
热议问题