I have embedded two images in this svg, but the images doesn't show up. What's wrong with what I did?
http://dl.dropbox.com/u/5363697/whirl_browserready.svg
MORE INFORMATION:
I do the image embedding with the following code, in case it helps:
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 )
It turned-out that the prefix
g_element.attrib[SVG('width')] = str( width )
in the width attribute is not required (the attribute itself is). Said prefix was causing Inkscape to strip the attribute from the document in a posterior post-processing step.