兩張圖片,一張是用戶上傳的圖片,另外一張是模板圖,中間是透明的,能夠製做相框,並保存。使用html2canvas對兩個img標籤進行截圖。在寫demo的時候html2canvas沒有報錯可是所截的是空白,若換成文字就能夠。javascript
找了半天才知道,若是截圖部分包含圖片的話,程序必須放在服務器下面進行,否則的話就是空圖片。css
##代碼實例html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="js/jquery.js"></script> <script src="js/html2canvas.js"></script> <script src="js/canvas2image.js"></script> </head> <style type="text/css"> img{ width: 500px; height: 300px; position: fixed; } #div1{ height: 500px; width: 100%; } #div2{ position: fixed; bottom: 0; background: red; } </style> <body> <div id="div1"> <img id="img1" src="img/01.jpg"> <img id="img2" src="img/02.jpg" style="width:300px"> </div> <div id="div2"></div> </body> <script type="text/javascript"> html2canvas($('#div1'), { onrendered: function(canvas) { var oImgPNG = Canvas2Image.saveAsPNG(canvas, true); $('#div1').hide(); $('#div2').html(oImgPNG); }, width: 500, height: 500 }); </script> </html>