I am taking input(x,y, height, and width) from user to create a dynamic img in SVG through javascript.
It works fine but Height and width don't scale according to the value (it act as padding across the image). Height and width doesn't increases or decreases.
Here is my code(only relevant to question) :
Grp = document.createElementNS('http://www.w3.org/2000/svg', 'g')
Grp.setAttributeNS(null, "id", "newGrp");
svg.appendChild(Grp);
Img = document.createElementNS('http://www.w3.org/2000/svg', 'image');
Img.setAttributeNS(null, "id", "newImg");
Img.setAttributeNS(null, "x", x);
Img.setAttributeNS(null, "y", y);
Img.setAttributeNS(null, "height", height);
Img.setAttributeNS(null, "width", width);
Img.setAttributeNS(null, "style", "height:" + height + "px;width:" + width+"px;");
//Img .setAttributeNS(null, "style", "background-size:" + height + " " + width + ";");
Img .setAttributeNS('http://www.w3.org/1999/xlink', "href", PathofImage);
Grp.appendChild(Img);
Here is how SVG look
<svg xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"
width="500" height="100" overflow="visible" x="500"
y="500" viewBox="0 0 700 700">
<g id="newGrp">
<image id="newImg" x="108.3" y="375.3" height="48.5" width="144.3"
style="background-size:38.5 134.3;"
xlink:href="pathofImage"></image>
<g>
<svg>
I have also tried background-size but it doesn't work as well.
How can I achieve this?