html2canvas PNG 이미지 생성 및 다운로드

1259 단어 전단 기초 지식



 
 var content = document.getElementById("mainB"); 
 
//  canvas 
function btnSave(){
	html2canvas(content, {
        onrendered: function(canvas) {
        	// 
        	canvas.setAttribute('id','thecanvas');
			// 
			// var value= canvas.getAttribute('id');
            document.getElementById('images').appendChild(canvas);
            Download();
        }
	});
} 
function Download(){
	var oCanvas = document.getElementById("thecanvas");
	/* png*/
	//  
	var img_data1 = Canvas2Image.saveAsPNG(oCanvas, true).getAttribute('src');
	saveFile(img_data1, 'img');


	
}    
function saveFile(data, filename){
    var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
    save_link.href = data;
    save_link.download = filename;
   
    var event = document.createEvent('MouseEvents');
    event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    save_link.dispatchEvent(event);
};
	

좋은 웹페이지 즐겨찾기