gpt4 book ai didi

jQuery 网络摄像头插件 - 保存图像

转载 作者:行者123 更新时间:2023-12-01 03:52:40 25 4
gpt4 key购买 nike

我很难使用 jquery 网络摄像头插件保存从网络摄像头捕获的图像。这是代码..

$(document).ready(function(){
$("#camera").webcam({
width: 320,
height: 240,
mode: "save",
swffile: "jscam.swf",
});

});

我正在使用“保存”模式。在 body 部分..

<div id="camera"></div>
<a href="javascript:webcam.save('upload.php');void(0);">capture</a>

在 upload.php 部分..

$str = file_get_contents("php://input");
file_put_contents("upload.jpg", pack("H*", $str));

我也尝试了回调模式还是不行。看来博客本身的例子还不够

http://www.xarg.org/project/jquery-webcam-plugin/

[更新]

终于成功了!我可以捕捉图像。我挖出了页面的源代码,并在我的代码中添加了一个 onload 事件监听器:D

现在我唯一的问题是如何保存图像。该博客没有明确说明如何进行。它只是给出了代码

webcam.save('/upload.php');

老实说,我不知道该怎么处理它,不像他提供的 php 代码。我应该将其放在链接中吗?或者编辑 onCapture 部分

最佳答案

您需要执行一些 PHP 操作,这是来自 JPEGCam 项目的基本上传脚本

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename = date('YmdHis') . '.jpg';
$result = file_put_contents( '/path/to/file/store/or/site/' . $filename,
file_get_contents('php://input') );
if (!$result) {
print "ERROR: Failed to write data to $filename, check permissions\n";
exit();
}

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/'
. $filename;
print "$url\n";

?>

关于jQuery 网络摄像头插件 - 保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6570283/

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