用html2canvas保存每x分钟

时间:2022-12-08 01:07:49

I want to make a badge from a div like a game badge, I got html2canvas to save to my server by click a button, how ever I want it so I don't need to press a button every time I want a updated image.

我想从div中创建一个徽章就像游戏徽章一样,我让html2canvas通过点击一个按钮保存到我的服务器上,无论我想要它到什么程度,所以我不需要每次我想要更新的图像时都按下一个按钮。

The script i'm using is

我使用的脚本是。

function capture() {
    $('#box').html2canvas({
        onrendered: function (canvas) {
            $('#img_val').val(canvas.toDataURL("image/png"));
            document.getElementById("myForm").submit();
        }
    });
}

The save page is:

保存页面:

    <?php
//Get the base-64 string from data
$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);
?>
<h2>Save the image and show to user</h2>
<table>
    <tr>
        <td>
            <a href="img.png" target="blank">
                Click Here to See The Image Saved to Server</a>
        </td>
        <td align="right">
            <a href="index.php">
                Click Here to Go Back</a>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <br />
            <br />
            <span>
                Here is Client-sided image:
            </span>
            <br />
<?php
//Show the image
echo '<img src="'.$_POST['img_val'].'" />';
?>

So is there anyway of saving the div to image every x minutes?

那么,是否有办法将div保存为每x分钟一次的图像呢?

1 个解决方案

#1


0  

You can pass capture function to a setInterval function, which receives intervals in milliseconds as the second argument.

您可以将捕获函数传递给setInterval函数,该函数以毫秒作为第二个参数。

function capture() {
  $('#box').html2canvas({
    onrendered: function (canvas) {
        $('#img_val').val(canvas.toDataURL("image/png"));
        document.getElementById("myForm").submit();
    }
  });
}

setInterval(capture, 2000);

This will call capture function every 2 second.

这将每2秒调用捕获函数。

#1


0  

You can pass capture function to a setInterval function, which receives intervals in milliseconds as the second argument.

您可以将捕获函数传递给setInterval函数,该函数以毫秒作为第二个参数。

function capture() {
  $('#box').html2canvas({
    onrendered: function (canvas) {
        $('#img_val').val(canvas.toDataURL("image/png"));
        document.getElementById("myForm").submit();
    }
  });
}

setInterval(capture, 2000);

This will call capture function every 2 second.

这将每2秒调用捕获函数。