thecore7 thecore7 - 4 months ago 10
PHP Question

How to activate webcamera to take snapshot with js

I am making backend application on php and was curious is it possible to take a snapshot with webcamera via js instead of taking picture , downloading it to the hard drive and than to upload it via input file?
I hope you understand the core of the issue! The idea is to upload image directly after user press button "Take snapshot"

Adi Adi
Answer

Here is a js library that uses flash only in a HTML5 fallback situation:

https://github.com/jhuckaby/webcamjs

    <script src="librarypath.js"></script>

    <div id="cameraId"></div>
    <div id="cameraResultId"></div>

    <script language="JavaScript">
        Webcam.attach( '#cameraId' );

        function snapshot() {
            Webcam.snap( function(data_uri) {
SendJson = {};                
SendJson["image"] = data_uri;
                SendJson=JSON.stringify(SendJson);


                $.ajax({
                    type: 'POST',
                    url: respective_page.php,
                    dataType: 'json',
                    contentType:'application/json',
                    data:SendJson,
                    success: function(data){

                        alert('Uploaded Succefully')
                    },
                    error: function(jqXHR, textStatus, errorThrown){
                       handleErrors('Error: ' , textStatus , errorThrown);
                    }
                });

            } );
        }
    </script>

    <a href="javascript:void(snapshot())">Snapshot</a>
Comments