Javascript 使用canvas捕获div在php中为图形提供空白图像
我曾尝试捕获div。它捕获和保存内容和图像。但当我试图用画布捕捉一个图形时,它会给出一个空白图像。它需要图像的高度和宽度,但它显示白色空白图像 我使用了JPower图形 这是外接程序索引文件:Javascript 使用canvas捕获div在php中为图形提供空白图像,javascript,php,jquery,html,canvas,Javascript,Php,Jquery,Html,Canvas,我曾尝试捕获div。它捕获和保存内容和图像。但当我试图用画布捕捉一个图形时,它会给出一个空白图像。它需要图像的高度和宽度,但它显示白色空白图像 我使用了JPower图形 这是外接程序索引文件: <script type="text/javascript"> function capture() { $('#target').html2canvas({ onrendered: function (canvas) {
<script type="text/javascript">
function capture() {
$('#target').html2canvas({
onrendered: function (canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/png"));
//Submit the form manually
document.getElementById("myForm").submit();
}
});
}
</script>
<form method="POST" enctype="multipart/form-data" action="save.php" id="myForm">
<input type="hidden" name="img_val" id="img_val" value="" />
</form>
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
file_put_contents('img.png', $unencodedData);