Nodejs - How to show qr-image result in view

ぃ、小莉子 提交于 2019-12-04 08:29:37

You're trying to stuff a rendered image into a template engine; it's not going to work.

You should instead have an image tag in the template that points to a URL that responds with the image.

// Edit based on comment

router.get('/qr/:text', function(req,res){
   var code = qr.image(req.params.text, { type: 'png', ec_level: 'H', size: 10, margin: 0 });
   res.setHeader('Content-type', 'image/png');
   code.pipe(res);
}

Then in your html template, make an image tag with the src set to /qr/whatever text and you should be in good shape.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!