<script>
var inp=$(".inp").val();
var info=$(".title");
var save = $(".save");
let w = $(window).width();//圖片寬度
let h = $(window).height();//圖片高度
console.log(w+" "+h);
console.log("操作系統"+getOS());//選擇需要生成圖片的標籤, 將jQuery對象轉換爲dom對象,
var need = $("body").get(0);// 生成二維碼
$('.erweima').click(function(){jQuery('#qrcode').qrcode("http://www.baidu.com");})// 點擊轉成canvas,最後用於生成圖片
$('.picture').click(function(e){// 調用html2canvas插件html2canvas(need).then(function(canvas){// canvas寬度
var canvasWidth = canvas.width;// canvas高度
var canvasHeight = canvas.height;// 控制檯查看繪製區域的寬高
console.log('canvas:'+ canvasWidth+" "+canvasHeight);// 渲染canvas,這個時候將我們用於生成圖片的區域顯示出來
$(".need").show();// 將canvas轉爲圖片
var img = Canvas2Image.convertToImage(canvas, canvasWidth, canvasHeight);// 渲染圖片,並且加到頁面中查看效果
$(".need").html(img);// 保存// console.log(img.src)downloadFile('測試.png', img.src);});});// 下載圖片functiondownloadFile(fileName, content){
let aLink = document.createElement('a');
let blob =base64ToBlob(content);//new Blob([content]);
let evt = document.createEvent("HTMLEvents");
evt.initEvent("click",true,true);//initEvent 不加後兩個參數在FF下會報錯 事件類型,是否冒泡,是否阻止瀏覽器的默認行爲
aLink.download = fileName;
aLink.href = URL.createObjectURL(blob);// aLink.dispatchEvent(evt);
aLink.click()}//base64轉blobfunctionbase64ToBlob(code){
let parts = code.split(';base64,');
let contentType = parts[0].split(':')[1];
let raw = window.atob(parts[1]);
let rawLength = raw.length;
let uInt8Array =newUint8Array(rawLength);for(let i =0; i < rawLength;++i){
uInt8Array[i]= raw.charCodeAt(i);}returnnewBlob([uInt8Array],{type: contentType});}</script>