thecore7 thecore7 - 1 year ago 81
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 Source

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

    <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;

                    type: 'POST',
                    url: respective_page.php,
                    dataType: 'json',
                    success: function(data){

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

            } );

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