问题描述
我很难使用jquery网络摄像头插件保存从网络摄像头捕获的图像。
这里是代码..
im having a hard time saving the image captured from the webcam using the jquery webcam plugin.here's the code..
$(document).ready(function(){
$("#camera").webcam({
width: 320,
height: 240,
mode: "save",
swffile: "jscam.swf",
});
});
我正在使用'保存'模式。在身体部分..
i am using the 'save' mode. in the body part..
<div id="camera"></div>
<a href="javascript:webcam.save('upload.php');void(0);">capture</a>
..
$str = file_get_contents("php://input");
file_put_contents("upload.jpg", pack("H*", $str));
我也试过回调模式仍然无法正常工作。似乎博客本身没有足够的例子
i also tried the callback mode still doesnt work. it seems the blog itself has insufficient examples
[update]
终于搞定了!我可以拍摄图像。我挖出了页面的源代码,并在我的代码上添加了一个onload eventlistener:D
finally got it working! i can capture the images. i dug up the source code of the page and added an onload eventlistener on my code :D
现在我唯一的问题是如何保存图像。博客没有明确说明如何。它只是给了代码
now my only problem is how to save the image. the blog doesn't clearly specify how. it just gave the codes
webcam.save('/upload.php');
老实说我不知道该怎么做,不像他给的PHP代码。我应该把它放在一个链接中吗?或者编辑onCapture部分?
which is honestly i don't know what to do with it, unlike the php code he gave. should i put it in a link? or edit the onCapture part?
推荐答案
你需要做一点PHP这里是一个基本上传脚本,来自JPEGCam项目
You going to need to do a little PHP Here is a basic upload script, from the JPEGCam project
<?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网络摄像头插件 - 保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!