如何在javascript中将svg验证码数据集作为图像下载?

如何在javascript中将svg验证码数据集作为图像下载?,javascript,node.js,express,captcha,Javascript,Node.js,Express,Captcha,我正在使用npm模块svg验证码生成验证码。当我们创建一个新的验证码时,我们会得到一个包含 { isMath: false, // if true will be a simple math equation useFont: null, // Can be path to ttf/otf font file size: 5, // number of characters for string capthca

我正在使用npm模块svg验证码生成验证码。当我们创建一个新的验证码时,我们会得到一个包含

{
  isMath: false,           // if true will be a simple math equation
  useFont: null,          // Can be path to ttf/otf font file
  size: 5,                // number of characters for string capthca
  ignoreChars: '0o1i',    // characters to not include in string capthca
  noise: 3,               // number of noise lines
  color: true,            // if true noise lines and captcha characters will be randomly colored
                          // (is set to true if background is set)
  background: null,       // HEX or RGB(a) value for background set to null for transparent
  width: 150,             // width of captcha
  height: 50,             // height of captcha
  fontSize: 56,           // font size for captcha
  charPreset: null,       // string of characters for use with string captcha set to null for default aA-zZ

}
当我在html中将其呈现为图像时,我可以看到图像


app.get('/captcha', captcha.generate())

    app.get('/', function (req, res, next) {
      res.type('html')
      res.end(`
        <img src="/captcha"/>

        <form action="/test" method="post">

          <input type="text" name="captcha"/>

          <input type="submit"/>

        </form>
      `)
    })

app.get('/captcha',captcha.generate())
app.get('/',函数(req,res,next){
res.type('html')
res.end(`
`)
})

如何将此“/captcha”保存为图像?

这里,当我们说captcha.generate()时得到的验证码包含数据和文本

var new_Captcha=Captcha.generate()

新的验证码:{“文本”:“某些验证码值(例如:AuEr)”,“数据”:
..
}

由于我们获得的数据是html格式的,因此我们需要使用NF Base64转换器将此html转换为url,我们可以使用
btoa
(javascript内置函数)

将上述编码的Base64字符串附加到
数据:image/svg+xml;base64,
,我们得到浏览器上呈现图像的url。利用这个url,我们可以下载图像