I'm trying to build an SVG manually with data of a submitted form.
Now I want to add an image to the SVG like this:
<image x='" + parseFloat(element.left) + "' y='" + parseFloat(element.top) + "' width='" + parseInt(element.width) + "' height='" + parseInt(element.height) + "' xlink:href='" + element.data + "' />
If I parse my complete SVG code now it yields this:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="160" height="90">
<rect width="160" height="90" style="fill:rgb(255, 255, 255);stroke:rgb(0,0,0);stroke-width:0"></rect>
<img x="64" y="29" width="32" height="32" xlink:href="http://allette-bunt-tattoo.de/wp-content/themes/Allettebunt/images/twitter-icon.png">
</svg>
Which looks correct for me (except the image tag, converted from <image>
to <img>
)...
Now the strange thing is the output to the browser/DOM:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="160" height="90">
<rect width="160" height="90" style="fill:rgb(255, 255, 255);stroke:rgb(0,0,0);stroke-width:0"></rect>
</svg>
<img x="64" y="29" width="32" height="32" xlink:href="http://allette-bunt-tattoo.de/wp-content/themes/Allettebunt/images/twitter-icon.png">
The SVG is rendered correctly but the image is shown beside the SVG.
I searched for a couple "SVG add image" tutorials and all of them seem like doing it the same way I do and it works for them. What's wrong in my case?
//EDIT I build the SVG like this:
var svg = $("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='" + parseInt(stampy.editor.width) + "' height='" + parseInt(stampy.editor.height) + "'></svg>");
svg.append("<rect width='" + parseInt(stampy.editor.width) + "' height='" + parseInt(stampy.editor.height) + "' style='fill:" + stampy.editor.background + ";stroke:rgb(0,0,0);stroke-width:" + (parseInt(stampy.editor.border) * 2) + "' />");
svg.append("<image x='" + parseFloat(element.left) + "' y='" + parseFloat(element.top) + "' width='" + parseInt(element.width) + "' height='" + parseInt(element.height) + "' xlink:href='" + element.data + "' />");
svg = $('<div>').append(svg.clone()).html();
//alert(svg);
$(this).html(svg);