html2canvas跨域照片截取方法
html2canvas是一款强大的canvas截图插件,但是对于跨域的图片竟然无法截取,怎么办
其实很简单,html2canvas提供了跨域解决办法发,在配置中加入
useCORS: true,
backgroundColor: null
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>BFWONE.JS DEMO PAGE</title> <script id="bfwone" data="dep=jquery.17&err=0" src="http://repo.bfw.wiki/bfwrepo/js/bfwone.js"></script> </head> <body> <div id="capture" style="background: #f5da55;transform:scale(1)"> <img src="http://repo.bfw.wiki/bfwrepo/image/5d653be845a41.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" /> <h4 style="color: #000; ">Hello world!</h4> </div> <script> bready(function() { use(["html2canvas.min"], function() { html2canvas(document.querySelector("#capture"), { useCORS: true, backgroundColor: null }).then(canvas => { document.body.appendChild(canvas) }); }); }); </script> </body> </html>
网友评论0