jQuery 网络摄像头:保存模式导致:“错误:未编译保存模式。”

发布于 2024-12-06 13:12:49 字数 2285 浏览 1 评论 0原文

我目前正在实现照片快照功能,以允许用户通过网络摄像头设置他们的个人资料照片。为了实现此目的,我使用 jQuery 网络摄像头插件

问题的出现是因为我想让用户单击“拍照”并将快照保存到服务器的适当位置以供用户图像 API 检索。

看起来这应该很容易做到,但由于某种原因我遇到了问题。按下按钮时,照片拍摄正常,但保存无法正确执行,因为我收到错误 错误:未编译保存模式。

注意:我的保存 URL包含一个 hash 变量,例如 ?hash=XYZ123。这就是图像在 PHP 文件中的命名方式。

我尝试从 URL 中删除 hashref 变量,认为这可能会导致图像数据以某种方式丢失/忽略,但这没有产生任何区别。有人能看到我在这里做错了什么吗?我很确定我遵循了文档以及位于此处的其他几篇文章,就像这个

屏幕截图

在此处输入图像描述

HTML

<div id="camera"></div> <!-- WebCam Live Display -->
<div id="wcStatus"></div> <!-- Debug Text Display -->

<button onclick="showWebcam();">Use Webcam Instead</button>

<!--This button is normally hidden until camera initialized, but for sake for demo-->
<button onclick="saveWebCam('XYZ123', '66');">Take a picture!</button>

JS

function showWebcam(){
    $("#camera").webcam({
        width: 320,
        height: 240,
        mode: "save",
        swffile: "/webcam/jscam_canvas_only.swf",
        debug: function(type, string) {
            $('#wcStatus').append(type + ": " + string + '<br /><br />');
        }     
    }); 
}
function saveWebCam(hash, id){
    var url = '/accountFiles/userImages/saveFromWebCam.php?hash=' + hash + '&ref=' + randomString(30);
    $('#wcStatus').append('Capturing: ' + url + '<br /><br />');
    webcam.capture();
    webcam.save(url);
}

PHP (saveFromWebCam.php)

<?php
    $destFile=$_REQUEST['hash'].'.jpg';
    $str = file_get_contents('php://input');
    file_put_contents($destFile, pack("H*", $str));     
?>

调试输出

通知:相机已启动

捕获:/accountFiles/userImages/saveFromWebCam.php

通知:捕获开始。

通知:捕获完成。

错误:未编译保存模式。

I am currently implementing a photo snapshot function to allow users to set their profile photo via webcam. To accomplish this, I am using jQuery Webcam Plugin.

The problem arises in that I would like to have the user click a "Take Photo" and have the snapshot saved to the server in the appropriate location to be retrieved by the user image APIs.

It seems this should be pretty easy to do, but for some reason I am running into problems. When my button is pressed, the photo capture takes place alright, but the saving doesn't execute properly as I am receiving the error error: No save mode compiled in.

NOTE: My Save URL contains a hash variable like ?hash=XYZ123. This is how the image is named in the PHP file.

I've attempted to remove the hash and ref variable from the url, thinking perhaps this caused the image data to be lost/ignored somehow, but that yielded no difference. Can anyone see something I did wrong here? I am pretty sure I followed the documentation as well as several other posts located here on SO, like this one.

Screenshot

enter image description here

HTML

<div id="camera"></div> <!-- WebCam Live Display -->
<div id="wcStatus"></div> <!-- Debug Text Display -->

<button onclick="showWebcam();">Use Webcam Instead</button>

<!--This button is normally hidden until camera initialized, but for sake for demo-->
<button onclick="saveWebCam('XYZ123', '66');">Take a picture!</button>

JS

function showWebcam(){
    $("#camera").webcam({
        width: 320,
        height: 240,
        mode: "save",
        swffile: "/webcam/jscam_canvas_only.swf",
        debug: function(type, string) {
            $('#wcStatus').append(type + ": " + string + '<br /><br />');
        }     
    }); 
}
function saveWebCam(hash, id){
    var url = '/accountFiles/userImages/saveFromWebCam.php?hash=' + hash + '&ref=' + randomString(30);
    $('#wcStatus').append('Capturing: ' + url + '<br /><br />');
    webcam.capture();
    webcam.save(url);
}

PHP (saveFromWebCam.php)

<?php
    $destFile=$_REQUEST['hash'].'.jpg';
    $str = file_get_contents('php://input');
    file_put_contents($destFile, pack("H*", $str));     
?>

Debug Output

notify: Camera started

Capturing: /accountFiles/userImages/saveFromWebCam.php

notify: Capturing started.

notify: Capturing finished.

error: No save mode compiled in.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红颜悴 2024-12-13 13:12:49

这是您的错误:

swffile: "/webcam/jscam_canvas_only.swf",

应该是:

swffile: "js/jscam.swf",

引用插件网页

指向Flash影片的swf文件,该文件提供网络摄像头API。下载存档提供了两个 swf 文件:jscam.swf(提供完整的 API)和 jscam_canvas_only.swf(没有嵌入 JPEG 库(我嵌入了 AS 3 corelib 的调整后的 JPGEncoder))。因此,该文件只有原始文件的三分之一。

This is your error:

swffile: "/webcam/jscam_canvas_only.swf",

should be:

swffile: "js/jscam.swf",

quote from plugin webpage:

Points to the swf file of the Flash movie, which provides the webcam API. There are two swf files provided via the download archive: jscam.swf, which provides the full API and jscam_canvas_only.swf which have no embedded JPEG library (I embedded an adjusted JPGEncoder of the AS 3 corelib). Thereby, the file is only one third as large as the original.

枫以 2024-12-13 13:12:49

通常情况下,时间限制迫使我寻找该项目的替代方案。我决定像网络上的许多人一样,使用 jpegCam 项目。我在大约 15 分钟内就启动并运行了它。简单的!我不删除这个问题的唯一原因是为了未来寻求此类知识的人。

As is often the case, time constraints have forced me to seek alternatives to this project. I have decided, as many all over the web have, to use the jpegCam Project. I got it up and running in about 15 minutes. SIMPLE! The only reason I am not deleting this question is for future seekers of such knowledge.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文