将HTML文件或者SVG代码文件转换成.svg形式的图片

论文代码画图(根据自己的论文要求画图)

以下为svg代码,根据自己论文画图,有部分删减

    <svg height="400" width="850" xmlns="http://www.w3.org/2000/svg">
      <style>
        .small {
          font: italic 30px sans-serif;
        }
      </style>
      <text x="45" y="97" class="small">r<tspan dy="5" font-size="15">min</tspan></text>
      <text x="195" y="97" class="small">r<tspan dy="5" font-size="15">1</tspan></text>
      <text x="345" y="97" class="small">r<tspan dy="5" font-size="15">2</tspan></text>
      <text x="495" y="97" class="small">r<tspan dy="5" font-size="15">3</tspan></text>
      <text x="645" y="97" class="small">r<tspan dy="5" font-size="15">4</tspan></text>
      <text x="795" y="97" class="small">r<tspan dy="5" font-size="15">max</tspan></text>

      <text x="242" y="350" class="small">r<tspan dy="5" font-size="15">min</tspan></text>
      <text x="340" y="350" class="small">r<tspan dy="5" font-size="15">1</tspan></text>
      <text x="430" y="350" class="small">r<tspan dy="5" font-size="15">2</tspan></text>
      <text x="525" y="350" class="small">r<tspan dy="5" font-size="15">3</tspan></text>
      <text x="620" y="350" class="small">r<tspan dy="5" font-size="15">4</tspan></text>
      <text x="710" y="350" class="small">r<tspan dy="5" font-size="15">max</tspan></text>

      <line
        x1="50"
        y1="100"
        x2="50"
        y2="130"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
      <line
        x1="50"
        y1="115"
        x2="800"
        y2="115"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
      <line
        x1="800"
        y1="100"
        x2="800"
        y2="130"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />

      <defs>
        <marker
          id="triangle"
          markerUnits="strokeWidth"
          markerWidth="5"
          markerHeight="4"
          refX="0"
          refY="2"
          orient="auto"
        >
          <path d="M 0 0 L 5 2 L 0 4 z" />
        </marker>
      </defs>
      <path
        d="M 50,135 L 235,305"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />

      <defs>
        <marker
          id="triangle"
          markerUnits="strokeWidth"
          markerWidth="5"
          markerHeight="4"
          refX="0"
          refY="2"
          orient="auto"
        >
          <path d="M 0 0 L 5 2 L 0 4 z" />
        </marker>
      </defs>
      <path
        d="M 800,135 L 731,302"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M200 135 330 285"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M350 135 430 284"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M500 135 528 282"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M650 135 628 282"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />

      <g fill="none" stroke="black" stroke-width="4">
        <path stroke-dasharray="5,5" d="M200 100 200 130" />
        <path stroke-dasharray="5,5" d="M500 100 500 130" />
        <path stroke-dasharray="5,5" d="M650 100 650 130" />

        <path stroke-dasharray="5,5" d="M344 300 344 330" />
        <path stroke-dasharray="5,5" d="M626 300 626 330" />
      </g>

      <line
        x1="250"
        y1="300"
        x2="250"
        y2="330"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
      <line
        x1="720"
        y1="300"
        x2="720"
        y2="330"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
    </svg>

转换为svg图片; 供给在浏览器可另存为图片形式

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var svgCode = `<svg height="400" width="850" xmlns="http://www.w3.org/2000/svg">
      <style>
        .small {
          font: italic 30px sans-serif;
        }
      </style>
      <text x="45" y="97" class="small">r<tspan dy="5" font-size="15">min</tspan></text>
      <text x="195" y="97" class="small">r<tspan dy="5" font-size="15">1</tspan></text>
      <text x="345" y="97" class="small">r<tspan dy="5" font-size="15">2</tspan></text>
      <text x="495" y="97" class="small">r<tspan dy="5" font-size="15">3</tspan></text>
      <text x="645" y="97" class="small">r<tspan dy="5" font-size="15">4</tspan></text>
      <text x="795" y="97" class="small">r<tspan dy="5" font-size="15">max</tspan></text>

      <text x="242" y="350" class="small">r<tspan dy="5" font-size="15">min</tspan></text>
      <text x="340" y="350" class="small">r<tspan dy="5" font-size="15">1</tspan></text>
      <text x="430" y="350" class="small">r<tspan dy="5" font-size="15">2</tspan></text>
      <text x="525" y="350" class="small">r<tspan dy="5" font-size="15">3</tspan></text>
      <text x="620" y="350" class="small">r<tspan dy="5" font-size="15">4</tspan></text>
      <text x="710" y="350" class="small">r<tspan dy="5" font-size="15">max</tspan></text>

      <line
        x1="50"
        y1="100"
        x2="50"
        y2="130"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
      <line
        x1="50"
        y1="115"
        x2="800"
        y2="115"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
      <line
        x1="800"
        y1="100"
        x2="800"
        y2="130"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />

      <defs>
        <marker
          id="triangle"
          markerUnits="strokeWidth"
          markerWidth="5"
          markerHeight="4"
          refX="0"
          refY="2"
          orient="auto"
        >
          <path d="M 0 0 L 5 2 L 0 4 z" />
        </marker>
      </defs>
      <path
        d="M 50,135 L 235,305"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />

      <defs>
        <marker
          id="triangle"
          markerUnits="strokeWidth"
          markerWidth="5"
          markerHeight="4"
          refX="0"
          refY="2"
          orient="auto"
        >
          <path d="M 0 0 L 5 2 L 0 4 z" />
        </marker>
      </defs>
      <path
        d="M 800,135 L 731,302"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M200 135 330 285"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M350 135 430 284"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)"
      />
      <path
        stroke-dasharray="10,5"
        d="M500 135 528 282"
        stroke="black"
        stroke-width="3"
        fill="none"
        style="marker-end: url(#triangle)
      </g>
      <line
        x1="250"
        y1="315"
        x2="720"
        y2="315"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
      <line
        x1="720"
        y1="300"
        x2="720"
        y2="330"
        style="stroke: rgb(0, 0, 0); stroke-width: 3"
      />
    </svg>`;
      var blob = new Blob([svgCode], { type: "image/svg+xml" });
      var url = URL.createObjectURL(blob);

      var img = new Image();
      img.src = url;

      document.body.appendChild(img);
    </script>
  </body>
</html>

套路

var svgCode = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><rect x='50' y='50' width='100' height='100' fill='red' /></svg>";

var blob = new Blob([svgCode], { type: 'image/svg+xml' });
var url = URL.createObjectURL(blob);

var img = new Image();
img.src = url;

document.body.appendChild(img);

在浏览器中可以另存为

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值