gpt4 book ai didi

javascript - 有没有可能让javascript来截图?

转载 作者:行者123 更新时间:2023-12-02 16:54:07 25 4
gpt4 key购买 nike

有点远,但是有一个 JavaScript 函数/进程可以自动截取指定区域的屏幕截图,并将图片输出到我的计算机上的文件夹中。理想情况下,它能够放入循环中,以便为每次循环迭代拍摄一张照片。

这完全有可能吗?

最佳答案

如果您有安装了 PHP 的 Web 服务器,您可以使用 wkhtmltoimage 进行模拟。 。要每 5 秒生成一个新文件,您的 JS 将为:

$(document).ready(function() {
function takeImage() {
$.post(
'htmltoimage.php',
{ currentUrl : window.location + "?stopTimer=1" }, // data that your script might need
function(data) {
if (data.url !== undefined) {
console.log("The URL where you can download your image is " + data.url);
}
},
'json' // use JSON for expected return type
);
}
var startTimer = <?php echo (isset($_POST['stopTimer']) ? "false" : "true"); ?>
if (startTimer) { setTimeout(takeImage, 5000); }
});

您的 PHP 文件只需使用 wkhtmltoimage 即可转到您的 URL。最简单的形式:

<?php
function() {
$outputLocation = "/images/output_" . strtotime(date()) . ".png";
// assuming wkhtmltoimage is in your PATH (otherwise specify full path to executable below)
`wkhtmltoimage $_POST['currentUrl'] $outputLocation`;
return array('url' => $outputLocation);
}
?>

然后您可以使用 ImageMagick 或类似的 PHP 图像处理库将其裁剪到您想要的位置。

这也可以使用 Adob​​e AIR 或任何使用 WebKit 的程序来实现。

关于javascript - 有没有可能让javascript来截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26310247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com