如何为svg元素设置宽度和高度的背景图像或颜色?

时间:2017-05-31 13:17:49

标签: javascript php jquery canvas svg

我有多个svg元素,并且必须将其保存为php或javascript中的svg格式文件我试图将svg元素保存到画布中并将文本元素顶部和左侧放置以将其保存为svg格式文件。如何保存svg元素与白色背景和位置左上方的两个svg元素

<canvas id="canvas" width="500" height="500"></canvas>

     var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');

  var jArray= <?php echo json_encode($items ); ?>;

      //console.log(jArray);
     jQuery.each(jArray,function(index, value){
 // console.log('My array has at position ' + index + ', this value: '     +       value['svg']);
   //console.log(jArray[index]['svg']);

  //console.log("value[" + index + "]);

console.log(jArray[index]['svg']);
   <svg width="248" height="109" viewBox="-2.48333740234375 0 248 109" xmlns="http://www.w3.org/2000/svg"><text>hello<text></svg>
<svg width="222" height="112" viewBox="-2.48333740234375 0 248 109" xmlns="http://www.w3.org/2000/svg"><text>hello<text></svg>

0 个答案:

没有答案