[英]image rendering blurry when using html to canvas, using JavaScript and php
I am trying ot convert html elements to image using the following code, but text int eh image getting an blurry text. 我正在尝试使用以下代码将html元素转换为图像,但是图像中的文本变得模糊的文本。 any one can help me on this., here is the code 任何人都可以帮助我。,这是代码
setTimeout( function(){
//get the div content
div_content = document.querySelector("#container_inc");
html2canvas(div_content).then(function(canvas) {
//change the canvas to jpeg image
data = canvas.toDataURL('image/jpeg');
$.post('<?php echo base_url()?>index.php/mailsend/save_jpg', {data: data}, function(res)
{});
context.clearRect(0, 0, canvas.width, canvas.height);
});
} , 2000 );
$email_bodymsg = '';
$imgname = $this->session->userdata("sess_imgname");
echo $email_bodymsg = '<div><img src="http://xxx.xxx.xxx.xx/sample/user-image/'.$imgname.'.jpg" ></div>';
public function save_jpg()
{
$random ='Main-Data-Dashboard'.rand(100, 1000);
$this->session->set_userdata("sess_imgname", $random);
$savefile = file_put_contents("assets/user-image/$random.jpg", base64_decode(explode(",", $_POST['data'])[1]));
if($savefile){
echo $random;
}
}
Did you set the canvas's width
and height
, I think maybe this cause the 'blurry',like: 您是否设置了画布的width
和height
,我认为这可能导致“模糊”,例如:
<canvas width='1920' height='1080'></canvas>
canvas's default width
and height
is not very big, maybe you can try to set it bigger. canvas的默认width
和height
不是很大,也许您可以尝试将其设置为更大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.