我想使用HTML2Canvas将div保存为图像,我使用的是Ie10 +,下面是我的代码
html2canvas([document.getElementById('bgcolor')], {
letterRendering: true,
allowTaint: true,
imageSmoothingEnabled: true,
onrendered: function(canvas) {
var img = canvas.toDataURL("image/png",'1.0');
var output = img.replace('data:image/png;base64,', 'image/octet-stream');
var output = encodeURIComponent(img);
var Parameters = "image=" + output + '&template=' + '<?php echo $this->session->userdata('templatimg'); ?>';
img.webkitImageSmoothingEnabled = false;
img.mozImageSmoothingEnabled = false;
img.imageSmoothingEnabled = false;
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>saveimage.php",
data: Parameters,
success: function(data) {
}
});
}
}).done(function() {
});
}
});
此代码正常运行但图像拉伸,质量也很低。在PHP中我使用Imagick来保存图像。在chrome和Firefox中没有问题。