【问题标题】:Embedded bitmaps in svg not showingsvg中的嵌入位图未显示
【发布时间】:2013-02-06 19:38:07
【问题描述】:

我在这个 svg 中嵌入了两个图像,但图像没有显示出来。我做错了什么?

http://dl.dropbox.com/u/5363697/whirl_browserready.svg

更多信息:

如果有帮助,我会使用以下代码进行图像嵌入:

    xpath_expr = '//*[@{1}="{0}"]'.format(layername, INKSCAPE_XPATH('label') )
    layer_el = svg_doc.xpath( xpath_expr,
                              namespaces = NE_NS_MAP
                              )[0]
    obj_id = layer_el.attrib['id']
    # Keep it safe somewhere, now export that little element as an image
    output_el = tempfile.NamedTemporaryFile( 
        suffix='_temp.svg' )
    cmd_line = [
        'inkscape',
        '--export-id=' + obj_id,
        '--export-id-only',
        '--export-area-drawing',
        '--export-dpi=90', # Change here if required
        '--export-png=' + output_el.name,
        REL_SIMPLIFIED_LOCATION

        ]
    subprocess.check_call( cmd_line )

    # Now load back the file, as a 'buffer'
    whole_file = output_el.read()
    assert len( whole_file ) > 0
    bf = base64.b64encode( whole_file )
    # Change that 'g' element by an 'image' element
    g_element = etree.Element(SVG('image') )
    g_element.attrib[XLINK('href')] = "data:image/png;base64," + bf
    (width, height) = get_object_size( obj_id )
    print(width,height)
    g_element.attrib[SVG('width')] = str( width )
    g_element.attrib[SVG('height')] = str( height )
    svg_doc.replace( layer_el, g_element )

【问题讨论】:

    标签: html svg uri inkscape


    【解决方案1】:

    原来是前缀

      g_element.attrib[SVG('width')] = str( width )
    

    中的width属性不是必需的(属性本身就是)。所述前缀导致 Inkscape 在后处理步骤中从文档中删除属性。

    【讨论】:

      猜你喜欢
      • 2011-12-01
      • 2017-02-03
      • 2017-05-18
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      • 2016-12-22
      • 2020-12-19
      相关资源
      最近更新 更多